你把 echo "fail" 改成
echo mysql_error();
就真相大白了!orderNo 是自增的,也就是主键
而主键是不可重复的
你给他赋予 $num 的值,那就有可能违规了
既然你在插入时开列了字段名,那自增字段就不需要也在其中了
$sql="INSERT INTO order(cusNo,orderDate,orderSum,orderAddress) VALUES ('$_SESSION[admin]', '$time','$sum','$_POST[orderAddress]')";
echo mysql_error();
就真相大白了!orderNo 是自增的,也就是主键
而主键是不可重复的
你给他赋予 $num 的值,那就有可能违规了
既然你在插入时开列了字段名,那自增字段就不需要也在其中了
$sql="INSERT INTO order(cusNo,orderDate,orderSum,orderAddress) VALUES ('$_SESSION[admin]', '$time','$sum','$_POST[orderAddress]')";
Error: 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(cusNo,orderDate,orderSum,orderAddress) VALUES ('1', '20140731','94','2')' at line 1
就还是我的插入语法有问题还是什么........
$sql="INSERT INTO `order`(cusNo,orderDate,orderSum,orderAddress) VALUES ('$_SESSION[admin]', '$time','$sum','$_POST[orderAddress]')";
Error: 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(cusNo,orderDate,orderSum,orderAddress) VALUES ('2', '20140731','94','111'' at line 1
说是有语法错误
我的数据表是这样的(这是一张订单表 用于购买时生成订单记录的)
echo $sql;
贴出结果看看
INSERT INTO order(cusNo,orderDate,orderSum,orderAddress) VALUES ('2', '20140731','94','1111')
Error: 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(cusNo,orderDate,orderSum,orderAddress) VALUES ('2', '20140731','94','1111' at line 1
我的代码:就是和#3一样的
$sql="INSERT INTO order(cusNo,orderDate,orderSum,orderAddress) VALUES ('$_SESSION[admin]', '$time','$sum','$_POST[orderAddress]')";
echo $sql;
echo"</br>";
if (!mysql_query($sql,$corn))
die('Error: ' . mysql_error());
else
echo "success";
?>
$sql="INSERT INTO 'order' (cusNo,orderDate,orderSum,orderAddress) VALUES ('$_SESSION[admin]', '$time','$sum','$_POST[orderAddress]')";
echo $sql;
没差耶 错误提示变成这样了:
INSERT INTO 'order' (cusNo,orderDate,orderSum,orderAddress) VALUES ('2', '20140731','94','1111')
Error: 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' (cusNo,orderDate,orderSum,orderAddress) VALUES ('2', '20140731','94','1' at line 1