gpt4 book ai didi

php - 一个查询中出现不同的 MySQL 语法错误

转载 作者:行者123 更新时间:2023-11-29 03:48:35 25 4
gpt4 key购买 nike

我有一个每次都失败的简单INSERT INTO 查询。奇怪的是,如果我取出错误最初指向的那一列,或者之前的那一列,我只会得到一个不同的错误。

这是查询:

mysql_query("insert into list_items
(list_id,position,item,small_image,large_image,asin,description,
author,publish_date,amazon_description) values
('$id','$key','$value','$small_image','$large_image','$asin',
'$descriptions[$key]','$authors[$key]','$publish_date','$amazon_description')")
or die(mysql_error());

我使用的示例数据是:

$key=1;
$value=mysql_real_escape_string("Harry Potter and the Sorcerer's Stone");
$small_image="some_image_url";
$large_image="some_image_url";
$asin="13412341234";
$descriptions[$key]="";
$authors[$key]="JK Rowling";
$publish_date="1999-09-08";
$amazon_description=mysql_real_escape_string($long_amazon_description);

我得到的错误是:

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 '1999-09-08')' at line 1

当我从查询中删除“publish_date”列时,我得到一个不同的错误,说:

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 '''','')' at line 1

所以我认为它一定与“作者”列有关,所以我也删除了它,留下了这个查询:

mysql_query("insert into list_items 
(list_id,position,item,small_image,large_image,
asin,description,amazon_description) values
('$id','$key','$value','$small_image','$large_image',
'$asin','$descriptions[$key]','$amazon_description') ")
or die(mysql_error());

...但我遇到了同样的错误。有人可以告诉我我在这里做错了什么吗?这是表结构:

CREATE TABLE IF NOT EXISTS `list_items` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`list_id` int(11) NOT NULL,
`position` int(11) NOT NULL,
`item` varchar(512) NOT NULL,
`item_added` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`voted_up` int(11) NOT NULL,
`voted_down` int(11) NOT NULL,
`small_image` varchar(128) NOT NULL,
`large_image` varchar(128) NOT NULL,
`asin` varchar(16) NOT NULL,
`description` mediumtext NOT NULL,
`author` varchar(128) NOT NULL,
`publish_date` varchar(16) NOT NULL,
`genre` varchar(128) NOT NULL,
`amazon_description` mediumtext NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=379 ;

查询打印为:

insert into list_items
(list_id,position,item,small_image,large_image,asin,description,
author,publish_date,amazon_description) values
('76','1','Harry Potter And The Sorcerer\'s Stone',
'http://ecx.images-amazon.com/images/I/51MU5VilKpL._SL160_.jpg',
'http://ecx.images-amazon.com/images/I/51MU5VilKpL.jpg','059035342X','',
'J.K. Rowling','1999-09-08',
'Harry Potter has no idea how famous he is. That\'s because he\'s being raised by his miserable aunt and uncle who are terrified Harry will learn that he\'s really a wizard, just as his parents were. But everything changes when Harry is summoned to attend an infamous school for wizards, and he begins to discover some clues about his illustrious birthright. From the surprising way he is greeted by a lovable giant, to the unique curriculum and colorful faculty at his unusual school, Harry finds himself drawn deep inside a mystical world he never knew existed and closer to his own noble destiny.')

重要编辑:

当查询简化为 insert into list_items (list_id,position) values ('82','1') 时,它仍然失败,这对我来说是完全无法解释的。

最佳答案

尝试转义这些

$small_image="some_image_url";
$large_image="some_image_url";

在包含在您的查询中之前

关于php - 一个查询中出现不同的 MySQL 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11324193/

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