gpt4 book ai didi

mysql - 为什么我会收到语法错误或访问冲突?

转载 作者:太空宇宙 更新时间:2023-11-03 11:48:26 26 4
gpt4 key购买 nike

当我尝试向数据库中插入内容时出现语法错误。我有以下代码,但我真的不知道自己做错了什么。

if(isset($_POST['imadbID']) || isset($_POST['comment'])|| isset($_POST['Title']) || isset($_POST['Year'])
|| isset($_POST['released']) || isset($_POST['Runtime'])|| isset($_POST['Actors'])||isset($_POST['Country']) || isset($_POST['Language'])
|| isset($_POST['Plot']) || isset($_POST['Poster']) || isset($_POST['Director']) || isset($_POST['Writer']) || isset($_POST['imdbRating']) || isset($_POST['tst'])){
$imdbid=json_decode($_POST['imdbID']); $comment=json_decode($_POST['comment']);
$title=json_decode($_POST['Title']); $year=json_decode($_POST['Year']); $released=json_decode($_POST['Released']);
$runtime=json_decode($_POST['Runtime']); $actor=json_decode($_POST['Actors']); $country=json_decode($_POST['Country']);
$lang=json_decode($_POST['Language']); $plot=json_decode($_POST['Plot']); $poster=json_decode($_POST['Poster']);
$director=json_decode($_POST['Director']); $writer=json_decode($_POST['Writer']); $rating=json_decode($_POST['imdbRating']);
$test=json_decode($_POST['tst']);
}
try {
$sql="INSERT INTO films (title,length,description,releasedate,bannerpath,language,imdbid,country,rating)
VALUES ($title,$runtime,$plot,$released,$poster,$lang,$imdbid,$country,$rating)";
$conn->exec($sql);
$film_id=$conn->lastInsertId($sql);
}
catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}

我浏览了与此相关的其他问题和答案,但似乎找不到解决方案。

我得到的错误

ERROR: SQLSTATE[42000]: Syntax error or access violation: 1064 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 ',,,,,,,6.5)' at line 2

最佳答案

缺少引号可能是语法错误的原因,但是您以不安全的方式使用 PDO,您不妨返回使用 mysql_*

试试这个..

$sql=$conn->prepare("INSERT INTO films (title,length,description,releasedate,bannerpath,language,imdbid,country,rating)
VALUES (:t,:r,:p,:re,:po,:s,:i,:c,:ra)");
$sql->execute(array(":t"=>$title, ":r"=>$runtime, ":p"=>$plot, ":re"=>$released, ":po"=>$poster,":s"=>$lang,":i"=>$imdbid, ":c"=>$country, ":ra"=>$rating));

关于mysql - 为什么我会收到语法错误或访问冲突?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37058562/

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