php - 如何将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()"></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"></i></a>
<a href="#deleteEmployeeModal" class="delete" name="delete" data-toggle="modal"><i class="material-icons" data-toggle="tooltip" title="Delete"></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">×</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
}
解决方案
尝试这个。
if(isset($_POST['deleteUser'])){
$member_id = $_POST['options'];
// write delete sql query here
}
推荐阅读
- php - 可以使用 FPDF 或 TCPDF 在第二行的第三个标签上开始打印吗?
- c# - 在多行 C 函数中解析参数
- swift - 粗糙金属光栅化
- javascript - 从 Javascript 中的方法引用同级属性
- r - 如何在 R data.frame 中查找和删除所有缺少数据的行块?
- regex - 惰性运算符的正则表达式操作顺序
- internet-explorer - 注册 Internet Explorer 工具栏
- python - 仅提取字母和第一个数字
- r - 从谷歌驱动器导入工作表时 R tbl 和数据框中的子集错误
- node.js - 除非它!=原始值,否则无法更改 Mongoose 字段类型