大神看看哪错了,两天了
<br />$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')";<br /><br />if (mysql_query ( $sql, $conn )) {<br /> exit ( '添加成功!点击此处 <a href="../view/index.php">首页</a>' );<br />} else {<br /> echo '抱歉!添加数据失败:', mysql_error (), '<br />';<br /> echo '点击此处 <a href="javascript:history.back(-1);">返回</a> 重试';<br />}<br /><br />
登入後複製
运行结果:
抱歉!添加数据失败: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`------解决思路----------------------两个问题
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')";