dongshan7060 2011-11-09 16:34
浏览 27
已采纳

PHP购物车错误消息

I have an error message coming up with the following code I have used. The error message I am getting is:

 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

the code i have provided with you below starts from line 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(); 
        }
    ?>

Thanks for any help :)

  • 写回答

1条回答 默认 最新

  • duan2428 2011-11-09 16:38
    关注

    Order is a keyword. Use backtick character:

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

    In general, it's good not to use keywords in table/column names (like order, group, select , etc)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?