首页 > 解决方案 > 如何将php变量从一个div传递到同一页面中的另一个div而不是传递到另一个页面?

问题描述

我想从数据库中删除选定的数据。在删除之前我会要求用户确认,如果他同意只有数据将根据 member_id 删除数据库。为此,我希望包含页面的值(deleteUser.php)。如何做到这一点?。我知道使用表单和href将变量从一个页面传递到另一个页面。但是,这里我不知道如何传递变量。

任何人都可以帮助我吗?

我将通过 while 循环获得 member_id,例如 $userdetails['member_id']; 在代码中,

通过这样使用我可以做到。但我只想使用上面的代码。

<a href="http://localhost/Performance/login/deleteUser.php?" class="delete" name="delete" data-toggle="modal"><i class="material-icons" data-toggle="tooltip" title="Delete" Onclick="return ConfirmDelete()">&#xE872;</i></a>

我的代码是,

<?php
include_once "deleteUser.php";
?>
<table class="table table-striped table-hover">
                <thead>
                    <tr>
                        <th>
                            <span class="custom-checkbox">
                                <input type="checkbox" id="selectAll">
                                <label for="selectAll"></label>
                            </span>
                        </th>
                        <th>Username</th>
                        <th>Email</th>
                        <th>Role</th>
                    </tr>
                </thead>
                <tbody>
                <?php 
                while($userdetails = mysqli_fetch_array($res, MYSQLI_ASSOC)){
                   echo' <tr>
                        <td>
                            <span class="custom-checkbox">
                                <input type="checkbox" id="checkbox1" name="options[]" value="1">
                                <label for="checkbox1"></label>
                            </span>
                        </td>
                        <td>'.$userdetails['username'].'</td>
                        <td>'.$userdetails['email'].'</td>
                        <td>'.$userdetails['role'].'</td>
                        <td>
                            <a href="#editEmployeeModal" class="edit" data-toggle="modal"><i class="material-icons" data-toggle="tooltip" title="Edit">&#xE254;</i></a>
                            <a href="#deleteEmployeeModal" class="delete" name="delete" data-toggle="modal"><i class="material-icons" data-toggle="tooltip" title="Delete">&#xE872;</i></a>
                        </td>
                    </tr>';
                }?>
                </tbody>
            </table>
<div id="deleteEmployeeModal" class="modal fade">
        <div class="modal-dialog">
            <div class="modal-content">
                <form  method="post"  action="#" method="post" autocomplete="off">
                    <div class="modal-header">                      
                        <h4 class="modal-title">Delete Employee</h4>
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    </div>
                    <div class="modal-body">                    
                        <p>Are you sure you want to delete these Records?</p>
                        <p class="text-warning"><small>This action cannot be undone.</small></p>
                    </div>
                    <div class="modal-footer">
                        <input type="button" class="btn btn-default" data-dismiss="modal" value="Cancel">
                        <input type="submit" class="btn btn-danger" name="deleteUser" value="Delete">
                    </div>
                </form>
            </div>
        </div>
    </div>

我的 deleteUser.php 代码,

include_once '../Connection/dbconnect.php';
if(isset($_POST['deleteUser'])){
    //further codes will be here
}

在此处输入图像描述

在此处输入图像描述

标签: phpjqueryhtml

解决方案


尝试这个。

if(isset($_POST['deleteUser'])){
     $member_id = $_POST['options'];

     // write delete sql query here
}

推荐阅读