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 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题