dongyong6045 2014-06-15 15:16
浏览 169

使用PHP中的复选框删除MySQL记录

I'm trying to delete MySQL records in PHP using check boxes. I echoed each line and everything seems fine. The values and formats of the variables and arrays are correct.

But when I tried to echo $delete (which is the DELETE query) using VAR_DUMP(), it displays bool(false) (which means it doesn't get the value of the variable $emailID passed to it, right?). Why?

if (isset($_POST['deleteUser']) && isset($_POST['marked_user']))
{

    $marked_user = $_POST['marked_user'];


    foreach($marked_user as $user => $emailID)
    {
        $emailID = (int)$emailID;
        $delete = $base -> query( "DELETE FROM tickets.allowed_users WHERE allowed_users.emailID = '$emailID'");

    }
        header('Location: viewTickets.php?viewType=U');
}

This is the HTML part from a separate PHP file:

echo "<form action='addUser.php' method='POST'><table class='results3' align='center' cellspacing='0'>
            <tr><th class='head' id='headleft'  width='10%'></th>
                <th class='head' id='headright' colspan='4'>E-mail</th></tr>";

            while( $row = mysqli_fetch_array($sql) )
            {
                $email = $row['email'];
                $emailID = $row['emailID'];
                echo "<tr><td width='1%' class='results'><input type='checkbox' name='marked_user[]' value='$emailID'></td>
                        <td class='results' colspan='4'>" . $row['email']."</td></tr>";
            }
                echo "<td colspan='3'><input type='submit' class='button' name='deleteUser' value='Delete'></td></form>";

And this is my table:

CREATE TABLE allowed_Users
(
 emailID INT UNSIGNED NOT NULL AUTO_INCREMENT,
 email VARCHAR(50) NOT NULL,
 PRIMARY KEY( emailID )
);
  • 写回答

4条回答 默认 最新

  • douyuqing_12345 2014-06-15 15:29
    关注

    I think you need to concatenate a string like this:

    foreach($marked_user as $user => $emailID)
        {
            $emailID = (int)$emailID;
            $delete = $base -> query( "DELETE FROM tickets.allowed_users WHERE allowed_users.emailID = " . $emailID);
    
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python