2011-11-09 204 views
0

我有一個錯誤消息與我已經使用以下代碼。我得到的錯誤信息是:PHP Shoppinf購物車錯誤消息

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 values (34 1,1,250,2011-11-09,jahed)' at line 1 

我在下面提供的代碼從第1行開始!

<?php 

    session_start(); 
    ?> 
    <?php 
    if(!isset($_SESSION["username"])) 
    { 
     header("Location: shoppinglogin.php"); 
    } 
    ?> 

    <? 
     include("includes/db.php"); 
     include("includes/functions.php"); 

     if($_REQUEST['command']=='update'){ 
      $name=$_REQUEST['name']; 
      $email=$_REQUEST['email']; 
      $address=$_REQUEST['address']; 
      $phone=$_REQUEST['phone']; 

      $result=mysql_query("insert into customers values('','$name','$email','$address','$phone')"); 


     $max=count($_SESSION['cart']); 
      for($i=0;$i<$max;$i++){ 
       $orderid=mysql_insert_id(); 
       $pid=$_SESSION['cart'][$i]['productid']; 
       $q=$_SESSION['cart'][$i]['qty']; 
       $price=get_price($pid); 
       $date=date('Y-m-d'); 
       $user=$_SESSION['username']; 
       mysql_query("insert into order values ('$orderid','$pid','$q','$price','$date','$user')") 

        or die(mysql_error()); 

      } 
      die('Thank You! your order has been placed!'); 
      session_unset(); 
     } 
    ?> 

感謝所有幫助:)

回答

0

秩序是一個關鍵詞。使用反引號字符:

insert into `order` values('$orderid','$pid','$q','$price','$date','$user') 

在一般情況下,這是很好不要使用表/列名的關鍵字(如ordergroupselect等)

+0

太感謝你了...它的工作原理:d – Jahed