$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`
------解决思路----------------------
两个问题
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')";
友情提示:垃圾评论一律封号 加我微信:826096331拉你进VIP群学习群