-4

我正在尝试从表中删除所有行,但它不起作用。当我这样做时,echo $mydb->error; 它给了我以下信息:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM messages where from_user = ? and id = ?'

     $user = 'currentuser';
 if (isset($_POST['delete'])) {
 if(!empty($_POST['id'])){
 $id =  $_POST['id']; 


 $mydb = new mysqli('localhost', 'root', '', 'database');
 $stmt = $mydb->prepare("DELETE * FROM messages where from_user = ?  and id = ? ");
 echo $mydb->error;
 $stmt->bind_param('ss', $user, $id);
 foreach  ($_POST['id'] as $id) {
$stmt->execute();
}
echo"The Message deleted permanently";
}
}
4

2 回答 2

7

它应该是

$stmt = $mydb->prepare("DELETE FROM messages WHERE from_user = ?  AND id = ? ");

我会很感激使用mysqli_*函数而不是弃用的mysql_*

另外,不应该有*for DELETE;这不是正确的语法。

参考:

*语法与 SELECT 结合使用:

于 2013-08-17T04:47:45.303 回答
0

如果要删除用户的所有消息:

$stmt = $mydb->prepare("DELETE FROM messages where from_user = ?");
$stmt->bind_param('s', $user);
$stmt->execute();

如果要从表中删除所有行(小心!):

$stmt = $mydb->prepare("DELETE FROM messages");
$stmt->execute();
于 2013-08-17T04:58:57.047 回答