gpt4 book ai didi

php - 这个查询有什么问题

转载 作者:行者123 更新时间:2023-12-01 00:15:35 24 4
gpt4 key购买 nike

当我将记录插入到mysql时它给我错误

$sql = "insert into fish (fish_id,common_name,scientific_name,family,range,habitate,adult_size,identification,how_to_fish,image) values ('$com_name','$scientific_name','$family','$range','$habitate','$adult_size','$identification','$how_to_fish','$TARGET_PATH')";

错误是

Could not insert data into DB: 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 'range,habitate,adult_size,identification,how_to_fish,image) values ('Suwannee Ba' at line 1

当我转储查询时,它显示所有字段都是正确的。

string(737) "insert into fish (catch_id,common_name,scientific_name,family,range,habitate,adult_size,identification,
how_to_fish,image) values ('','Suwannee Bass','Micropterus notius','Centrarchidae (Sunfish)','United States (Florida, Georgia)',
'Freshwater: found in Suwannee and Ochlockonee river drainages of Florida and Georgia.',
'Up to 12 oz (.34 kg).','The smallest of the Black Bass; brown with dark markings along back and sides. Adult male has blue cheeks, breast, and belly.',
'Natural or artificial bait such as spinners, spoons, crankbaits, surface plugs, and plastic worms. Also can be caught via fly fishing using bugs, streamers, and bucktails. Live bait includes worms, crayfish, leeches, and minnows.',
'localhost/fish/pics/Smallmouth bass.png')"

请注意,我的 (catch_id) 是自动递增的,我在没有插入 catch_id 的情况下进行了检查,但同样的问题仍然存在

最佳答案

RANGE 是 MySQL 的保留字,因此您需要将 range 字段名用反引号括起来,否则 MySQL 会混淆。

insert into fish (fish_id,common_name,scientific_name,family,`range`,habitate...

那么你应该再次将你的表名和所有字段名放在反引号中。或者,重命名 range 字段,这样您就不必使用反引号了。

关于php - 这个查询有什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4561354/

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