我正在尝试向我的 DataTables 表添加一个删除按钮,但我不知道如何在按下删除按钮时发布所选行的用户名。
这是数据表的打印方式:
<div class="panel-body">
<div class="dataTable_wrapper">
<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th>Username</th>
<th>Email</th>
<th>Fullname</th>
<th>Class ID</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
while($listDetailsRow = mysql_fetch_array($listDetails)){
?>
<tr>
<td class="success"><?=$listDetailsRow['username']?></td>
<td class="info"><?=$listDetailsRow['email']?></td>
<td class="success"><?=$listDetailsRow['fullname']?></td>
<td class="info"><?=$listDetailsRow['class_id']?></td>
<td>
<form id='delete' action='deleteUser.php' method='post'>
<button type="submit" name="submit" class="btn btn-danger" href="deleteUser.php">
Delete
</button>
</form>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
所以它由 php 打印,直到所有打印完然后它停止...
deleteUsers.php文件如下:
include('../details.php');
$userDel = $_POST($listDetailsRow['username']);
echo $userDel;
// mysql_query("DELETE * FROM users WHERE username='$userDel'") or die(mysql_error());
我只是想让它从按下删除按钮的行打印用户名。
这可能吗?不太擅长 JS 或 Ajax,因此不胜感激。
最佳答案
<form id='delete' action='deleteUser.php' method='post'>
<input type='hidden' name='username' value="<?=$listDetailsRow['username'];?>" > <--add this line
<button type="submit" name="submit" class="btn btn-danger" href="deleteUser.php">
Delete
</button>
</form>
PHP:
$userDel = $_POST['username'];
关于PHP - DataTables 为 mysql_query 从表行发布用户名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31617395/