【问题标题】:PHP Shoppinf Cart Error MessagePHP购物车错误信息
【发布时间】:2023-03-06 23:56:01
【问题描述】:

我收到了一条错误消息,其中包含我使用的以下代码。我收到的错误消息是:

 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(); 
        }
    ?>

感谢您的帮助:)

【问题讨论】:

    标签: php mysql error-handling shopping-cart


    【解决方案1】:

    订单是一个关键字。使用反引号:

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

    一般来说,最好不要在表/列名中使用关键字(如ordergroupselect 等)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-16
      • 1970-01-01
      • 2015-04-16
      • 2015-06-09
      • 1970-01-01
      • 1970-01-01
      • 2016-03-17
      相关资源
      最近更新 更多