在做一个购物车网站。
我在home.php页面右侧iframe一个购物车,shopping_cart_form.php
本来一切都好好的,我在home.php里面每个商品加了几个text input什么的,在shopping_cart_form.php里面加了几句SQL。
但是我只要一点 添加进购物车,iframe里面就会出现:
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 '' at line 1我在shopping_cart_form.php里面看了,找不到SQL有啥错误。
后来我把shopping_cart_form.php换成以前正常的代码,居然也出现错误,以前是好好的啊!难道home.php里面改了几个input,可以影响到iframe里面的?//我就添加了这么几条
//这一个是好的,查数据库显示数据写进去了。
$query="INSERT INTO CART (username, dish_id, dish_qty, total_price, dest_id, shop_id) VALUES ('$username','$dish_id','$dish_qty','$dish_total_price','$dest_id','$shop_id')";
//下面两个有错误么?这个页面就这么多SQL了。
$query="SELECT * FROM DISH WHERE dish_id = '$dish_global_id'";
$query="INSERT INTO CART (username, dish_id, dish_qty, total_price, dest_id, shop_id) VALUES ('$username','$dish_global_id','$dish_global_qty','$dish_global_total','$dest_id','')";
我在home.php页面右侧iframe一个购物车,shopping_cart_form.php
本来一切都好好的,我在home.php里面每个商品加了几个text input什么的,在shopping_cart_form.php里面加了几句SQL。
但是我只要一点 添加进购物车,iframe里面就会出现:
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 '' at line 1我在shopping_cart_form.php里面看了,找不到SQL有啥错误。
后来我把shopping_cart_form.php换成以前正常的代码,居然也出现错误,以前是好好的啊!难道home.php里面改了几个input,可以影响到iframe里面的?//我就添加了这么几条
//这一个是好的,查数据库显示数据写进去了。
$query="INSERT INTO CART (username, dish_id, dish_qty, total_price, dest_id, shop_id) VALUES ('$username','$dish_id','$dish_qty','$dish_total_price','$dest_id','$shop_id')";
//下面两个有错误么?这个页面就这么多SQL了。
$query="SELECT * FROM DISH WHERE dish_id = '$dish_global_id'";
$query="INSERT INTO CART (username, dish_id, dish_qty, total_price, dest_id, shop_id) VALUES ('$username','$dish_global_id','$dish_global_qty','$dish_global_total','$dest_id','')";
我把''里面写上$shop_id 还是不行,而且我是想让shop_id为空的。
主要是 我把代码恢复到以前正常的了 还是出现错误
if(isset($_POST['btn_add'])&&$_POST['btn_add']=='Add to Cart')
{
if(isset($_SESSION['user']))
{
$username=$_SESSION['user'];
$dest_id=$_POST['destID'];
$shop_id=$_POST['shopID'];
$cat_id=$_POST['catID'];
$dish_id=$_POST['dishID'];
$dish_name=$_POST['dishName'];
$dish_qty=$_POST['textbox_qty'];
//choose drinks
$dish_global_id=$_POST['dish_select'];
$dish_global_qty=$_POST['global_dish_qty'];
//echo $dish_qty; $dish_price=$_POST['dishPrice'];
$dish_total_price=$dish_price * $dish_qty;
if($dish_global_id=='')
$isChose=false;
else
$isChose=true;
//echo " $dish_global_id";
if($dish_qty!='' || $dish_qty!=0)
{
$query="INSERT INTO CART (username, dish_id, dish_qty, total_price, dest_id, shop_id) VALUES ('$username','$dish_id','$dish_qty','$dish_total_price','$dest_id','$shop_id')";
$result=queryMysql($query);
if($isChose==false)
{
if($result)
{
header("Location:../shop.php?dest_id=$dest_id&shop_id=$shop_id&cat_id=$cat_id");
}
//echo "btn value IS set";
}
else
{
if($result)
{
$query="SELECT * FROM DISH WHERE dish_id = '$dish_global_id'";
$result=queryMysql($query);
$get_global_dish=mysql_fetch_array($result);
//$dish_global_name=$get_global_dish['dish_name'];
$dish_global_price=$get_global_dish['dish_price'];
if($dish_global_qty == 0 || $dish_global_qty == '')
$dish_global_qty = 1;
$dish_global_total=$dish_global_price * $dish_global_qty;
//echo "$query";
$query="INSERT INTO CART (username, dish_id, dish_qty, total_price, dest_id, shop_id) VALUES ('$username','$dish_global_id','$dish_global_qty','$dish_global_total','$dest_id','$shop_id')";
$result=queryMysql($query);
if($result)
{
header("Location:../shop.php?dest_id=$dest_id&shop_id=$shop_id&cat_id=$cat_id");
} }
}
}
else
header("Location:../shop.php?dest_id=$dest_id&shop_id=$shop_id&cat_id=$cat_id");
}
else
{
header("Location:../login.php");
}
}
不好意思 代码太长 就没发了
而且很奇怪啊 今天又突然好了 我什么代码都没改 自己就好了中间我把代码传到服务器里面 没有问题 但是本地显示还是出现SQL错误 但之后刷新下又好了
太奇怪了 这是啥问题?
$result=queryMysql($query);
if(!$result)
die("SQL:{$query}<br>Error:".mysql_error());
if(mysql_affected_rows() > 0){
……成功语句……
}else{
……失败语句……
}