gpt4 book ai didi

php - MySQL "INSERT INTO"-错误 : which quotation do I have to use?

转载 作者:太空宇宙 更新时间:2023-11-03 12:16:23 24 4
gpt4 key购买 nike

我正在为一个学校项目制作一个基于 Faroo.com ( http://www.faroo.com/hp/api/api.html ) API 的搜索引擎。我想索引 Faroo 的索引,以便用户(在我的情况下, children )可以投票赞成或反对个别结果。

我的 (PHP) 脚本是什么样的:

Look in the MySQL-database if the query exists.

yes => load the results from the database and show them to the user

no => load the results from Faroo, show those results to the user and store them in the database

我的数据库是这样的:

我正在从 Faroo API 获取存储在列中的所有数据,“id”列除外。

最后一部分(将 Faroo 数据存储在数据库中)出了问题:

for($x=0; $x<$tel; $x++){            
$sql = "INSERT INTO queries (`id`, `query`, `title`, `url`, `domain`, `kwic`, `votes`) VALUES (NULL, $q, $titles[$x], $urls[$x], $domains[$x], $kwics[$x], 0);";
echo '<br />'.$x.'e query: @'.$sql.'@';
if(!$resultaat = $db->query($sql)){
die('De query kon niet worden uitgevoerd: [' . $db->error . ']');
}
$resultaat = mysqli_fetch_array($resultaat);
}

$tel 是一个变量,用于计算我从 Faroo 获得的结果数量。它在这段代码之前被定义。当我运行这段代码时,我得到了一个很好的 MySQL 错误:

You have an error in your SQL syntax; check the manual thatcorresponds to your MySQL server version for the right syntax to usenear 'States Bureau of Mines - Wikipedia, the free encyclopedia,www.wikipedia.org' at line 1

我搜索了又搜索,但找不到 SQL 错误是什么。我觉得和字符串中的奇怪字符有关系,或者我引用的是假的?

亲切的问候,最大

最佳答案

我认为您需要对 varchar 列使用单引号 ',因此请按以下方式更改

$sql = "INSERT INTO queries (`id`, `query`, `title`, `url`, `domain`, `kwic`, `votes`) VALUES (NULL, '$q', '$titles[$x]', '$urls[$x]', '$domains[$x]', '$kwics[$x]', 0)";

你在查询的末尾还有一个额外的双引号,我删除了它,你不需要为 idvotes 列添加单引号,因为它们是 整数 字段

关于php - MySQL "INSERT INTO"-错误 : which quotation do I have to use?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21953600/

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