gpt4 book ai didi

php - SQL 错误只发生在 PHP 脚本中

转载 作者:行者123 更新时间:2023-11-29 05:21:00 25 4
gpt4 key购买 nike

<分区>

我很矛盾。我的 SQL 查询将仅通过 PhpMyAdmin 发送。如果我尝试通过 PHP 发送此特定查询,则会收到错误消息。当我将该确切查询复制到 PhpMyAdmin 时,它顺利通过。

INSERT INTO posts (id, content, poster, timestamp, tags) VALUES ('12056242', 'OMG I just got a #toyota', 'Clunker5', '09/12/14 08:43:36', 'toyota');INSERT INTO `tags` (tag, posts) VALUES ('toyota', 1) ON DUPLICATE KEY UPDATE posts=posts+1; UPDATE `tags` SET posts=posts+1 WHERE tag IN ('toyota');

这是与问题相关的 PHP 代码

//Ups one post for all tags entered by the user
if(!empty($tags)){
$tags1 = explode(",", $tags);
$tags_submit = join("','", $tags1);
$tags_insert = join("', 1), ('", $tags1);
$sql = "INSERT INTO posts (id, content, poster, timestamp, tags) VALUES ('$d', '$b', '".$_SESSION['username']."', '$c', '$tags');"
. "INSERT INTO `tags` (tag, posts) VALUES ('".$tags_insert."', 1)
ON DUPLICATE KEY UPDATE posts=posts+1;
UPDATE `tags` SET posts=posts+1 WHERE tag IN ('".$tags_submit."');";

$result = mysql_query($sql);
}else{
$sql = "INSERT INTO posts (id, content, poster, timestamp, tags) VALUES ('$d', '$b', '".$_SESSION['username']."', '$c', '$tags');";

$result = mysql_query($sql);
}
$error = mysql_error();
if($result){
echo "1";
}else{
echo error($sql, $error, "Tags: ".$tags, "Post: ".$b, "ID: ".$d);
}

错误是

SQL Response: 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 'INSERT INTO `tags` (tag, posts) VALUES ('toyota', 1), ('ohmygoodness', 1) ' at line 1.

编辑:既然我知道我不能执行多查询,我该如何执行此查询?

INSERT INTO `tags` (tag, posts) VALUES ('".$tags_insert."', 1)
ON DUPLICATE KEY UPDATE posts=posts+1;
UPDATE `tags` SET posts=posts+1 WHERE tag IN ('".$tags_submit."');

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