$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> 重试';}
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`