且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

删除多行,在PHP Ajax调用

更新时间:2023-12-03 12:01:16

所以,我终于能找到,我想我尝试了解决方案。我想,为什么不工作可能有一些与我试图用其原因 bindParam

So I was finally able to find a solution which I thought I tried. I think the reason why it wasn't working might have something to do with me trying to use bindParam.

下面是我改变了我的删除-user.php的 code到:

Here is what I changed my remove-user.php code to:

try{
    $ids = array($_GET['userID']);
    $inQuery = implode(',', $ids);
    $stmt = $db->prepare(
        'DELETE
         FROM users
         WHERE user_id IN(' . $inQuery . ')'
    );
    $stmt->execute($ids);
    $count = $stmt->rowCount();
    $user_removed = ''.$count.' user(s) deleted successfully.';
    $_SESSION['user_removed'] = $user_removed;
} catch (Exception $e){
    $error = '<strong>The following error occured:</strong>'.$e->getMessage();
    $_SESSION['error'] = $error;
}