PHP - DataTables Post 来自 table 行的用户名 mysql_query?

PHP - DataTables Post username from table row for a mysql_query?

我正在尝试向我的数据表添加删除按钮 table,但我不知道如何 post 按下删除按钮时所选行的用户名。

数据表的打印方式如下:

<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'];

您可以在按钮元素中使用 a 元素而不是表单。请参阅此代码:

<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>
        <!------------- New -------------->
        <?php
                $params = array( 'username' => $listDetailsRow['username'] );
                $href = "deleteUser.php?" . http_build_query($params);
          ?>
          <a class="btn btn-danger" href="<?php echo $href; ?>" > Delete </a>
          <!------------- End New -------------->
          </td>
      </tr>

                <?php
                 }
                ?>
</tbody>

在 deleteUser.php 中执行此操作:

$userDel = isset($_GET['username']) ? $_GET['username'] : null;