从表中删除*不起作用 [英] delete * from table not working
本文介绍了从表中删除*不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从表中删除所有行,但是它不起作用.当我做echo $mydb->error;
它给了我以下内容:
I am trying to delete all rows from table but it isn't working. when I do echo $mydb->error;
it gives me the below:
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";
}
}
推荐答案
应该是
$stmt = $mydb->prepare("DELETE FROM messages WHERE from_user = ? AND id = ? ");
对于使用mysqli_*
函数而不是已弃用的mysql_*
And I will appreciate for using mysqli_*
functions instead of deprecated mysql_*
此外,DELETE不应包含*
;那不是正确的语法.
Plus, there should not be a *
for DELETE; that is not the right syntax.
参考:
*
语法与SELECT一起使用:
The *
syntax is used in conjunction with SELECT:
这篇关于从表中删除*不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文