查询失败!您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册 [英] Query Failed!You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version

查看:41
本文介绍了查询失败!您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将其放入数据库.但是,我收到了一个意外错误,说:

I am trying to put this into the database. And I am getting an unexpected error, however, saying:

查询失败!您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行的order(Order_Date,Order_Time,Delivery_Charge,Delivery_Fname,Delivery_Lname,Delive"附近使用的正确语法.

Query Failed! 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(Order_Date,Order_Time,Delivery_Charge,Delivery_Fname,Delivery_Lname,Delive' at line 1.

这是我的 PHP:

<?php
//error_reporting(E_ERROR | E_PARSE);  
include("includes/db.php");
include("includes/functions.php");

if($_REQUEST['command']=='update')
{
$date     = date('Y-m-d');
$time     = time('H:i:s');
$charge   = $_REQUEST['ocharge'];
$fname    = $_REQUEST['ofname'];
$lname    = $_REQUEST['olname'];
$mobile   = $_REQUEST['omobile'];
$add1     = $_REQUEST['oadd1'];
$add2     = $_REQUEST['oadd2'];
$postcode = $_REQUEST['opostcode'];
$state    = $_REQUEST['ostate'];
$country  = $_REQUEST['ocountry'];
$weight   = $_REQUEST['oweight'];
$credit   = $_REQUEST['ocredit'];
$pin      = $_REQUEST['opin'];
$city     = $_REQUEST['ocity'];



    $result=mysql_query("insert into order(Order_Date,Order_Time,Delivery_Charge,Delivery_Fname,Delivery_Lname,Delivery_HP,Delivery_Street1,Delivery_Street2,Delivery_Postcode,Delivery_State,Delivery_Country,Total_Weight,Credit_No,Pin_No,Delivery_City) values ('$date',$time,$charge,'$fname','$lname',$mobile,'$add1','$add2',$postcode,'$state','$country',$weight,$credit,$pin,'$city')");

    if($result === FALSE)
    {
            die("Query Failed!".mysql_error().$result);
    }

    $orderid=mysql_insert_id();   


    $max=count($_SESSION['cart']);
    for($i=0;$i<$max;$i++)
    {
        $pid=$_SESSION['cart'][$i]['productid'];
        $q=$_SESSION['cart'][$i]['qty'];
        $price=get_price($pid);

        mysql_query("insert into order_detail (Order_ID,Product_ID,Order_Quantity,Sub_Total) values ('$orderid','$pid','$q','$price')");    
    }

    die('Thank You! your order has been placed!');

  }
  ?>

查询有什么问题?

推荐答案

ORDER 是一个 保留关键字.所以,你需要用反引号将它转义,就像这样:

ORDER is a reserved keyword. So, you'll need to escape it in backticks, like so:

INSERT INTO `order` ...

不在查询中使用保留关键字是更好的解决方案,但使用反引号将它们转义也可以.

Not using reserved keywords in your query would be the better solution, but escaping them with backticks works, too.

这篇关于查询失败!您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆