Home  >  Article  >  Backend Development  >  大神看看哪错了,两天了

大神看看哪错了,两天了

WBOY
WBOYOriginal
2016-06-23 13:48:53986browse

$sql = "INSERT INTO patient (order,name,age,sex,tel,qq,disease,media_from,area,ordertime,teshuyaoqiu,content,ordertag,beizhu,zixun_id)					VALUES('$order','$name','$age','$tel','$qq','$disease','$media_from','$area','$ordertime','$teshuyaoqiu','$content','$ordertag','$beizhu','$zixun_id')";if (mysql_query ( $sql, $conn )) {	exit ( '添加成功!点击此处 <a href="../view/index.php">首页</a>' );} else {	echo '抱歉!添加数据失败:', mysql_error (), '<br />';	echo '点击此处 <a href="javascript:history.back(-1);">返回</a> 重试';}


运行结果:
抱歉!添加数据失败: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 'order,name,age,sex,tel,qq,disease,media_from,area,ordertime,teshuyaoqiu,content,' at line 1
点击此处 返回 重试


回复讨论(解决方案)

order 是 mysql 保留字,挪作他用时应转义
`order`

要学会看错误报告
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  'order,name,age,sex,tel,qq,disease,media_from,area,ordertime,teshuyaoqiu,content,' at line 1

引号后的就是 mysql 认为有问题的部分

两个问题
1.order是关键字,最好不要用。
如果一定要用,需要用``括起来。
2.insert的字段数量与后面的values数量不匹配
字段15个,但values只有14个,少了sex

改成这样就可以了。
$sql = "INSERT INTO patient ( `order `,name,age,sex,tel,qq,disease,media_from,area,ordertime,teshuyaoqiu,content,ordertag,beizhu,zixun_id)  VALUES('$order','$name','$age', '$sex','$tel','$qq','$disease','$media_from','$area','$ordertime','$teshuyaoqiu','$content','$ordertag','$beizhu','$zixun_id')";

使用order的时候,应该使用''

order 是 mysql 保留字,挪作他用时应转义
`order`


涨姿势了
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn