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);
    
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集