gpt4 book ai didi

php - SQL 多查询特定

转载 作者:行者123 更新时间:2023-11-29 18:26:49 26 4
gpt4 key购买 nike

我遇到了一个非常具体的问题,我在网上找不到任何东西可以告诉我错误出在哪里。

我想一次传递两个 mysql 查询。单独来看,它们可以完美地工作,但组合在一起就会失败。我尝试过加入,添加 ;和 multi_queries 方法。一切都失败了。

现在我被这段代码困住了:

// data insertion
$sql = "INSERT INTO comments (id, name, email, comment, article_id, date) VALUES ('$id', '$name', '$email', '$comment', '$article_id', '$date')";
$sql.= "DELETE FROM comments_validation WHERE id = $id";

if ($conn->multi_query($sql) === TRUE) {
header('Location: http://url.com/index.php?success');

} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}

错误:

Error: INSERT INTO comments (id, name, email, comment, article_id, date) VALUES ('some values')DELETE FROM comments_validation WHERE id = 'some other value' 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 'DELETE FROM comments_validation WHERE id = 'some other value' at line 1

提前致谢!

最佳答案

您必须在此 sql 语句末尾添加 ;

$sql = "INSERT INTO comments (id, name, email, comment, article_id, date) VALUES ('$id', '$name', '$email', '$comment', '$article_id', '$date');";
^here

关于php - SQL 多查询特定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46114255/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com