Php 您的SQL语法有错误;近';订单(第1行的客户id、订单日期、订单总数、订单状态、订单城市、订单添加、订单和x27)

Php 您的SQL语法有错误;近';订单(第1行的客户id、订单日期、订单总数、订单状态、订单城市、订单添加、订单和x27),php,mysql,sql,Php,Mysql,Sql,这将出现在我的页面上方 <?php include("dbconnection.php"); if ($_SESSION["loggedin"] != "true") header("Location:memberlogin.php"); $cust_id = $_SESSION["cust_id"]; $result = mysql_query("select customer.*, product.*, order_details.* from customer, produc

这将出现在我的页面上方

<?php
include("dbconnection.php");

if ($_SESSION["loggedin"] != "true") 
header("Location:memberlogin.php");

$cust_id = $_SESSION["cust_id"];

$result = mysql_query("select customer.*, product.*, order_details.* from customer, product,      
order_details where customer.cust_id=$cust_id and product.pro_id=product.pro_id and    
order_details.order_details_id = order_details.order_details_id")or die(mysql_error());;

$row = mysql_fetch_assoc($result);  
?>

在这两者之间,我有另一个总代码

这就是下面出现的代码

<?php

if (isset($_POST["logoutbtn"]))
{
header("Location:logout.php");

}

if(isset($_POST["submitbtn"]))
{
$order_id=rand(1000,9999);
$order_date=date("Y-m-d"); 
$order_state=$_POST["order_state"];
$order_city=$_POST["order_city"];
$order_add=$_POST["order_add"];
$order_post=$_POST["order_post"];

echo ("insert into `order`
(cust_id, order_date, order_total, order_state, order_city, order_add, 
order_post)
values('$cust_id','$order_date', 
'$order_total', '$order_state', '$order_city','$order_add','$order_post')")or die(mysql_error());
?>
    <script type="text/javascript">
        alert("Order recorded.");
    </script>
<?php
header("Location:orderview3.php");
}

?>

您在列名周围使用单引号:

$insertQuery=mysql_query("insert into 'order'('cust_id', 'order_date', 'order_total',    
'order_state', 'order_city', 'order_add', 'order_post')values('$cust_id','$order_date', 
'$order_total', '$order_state', '$order_city','$order_add','$order_post')")
请尝试以下方法:

$insertQuery=mysql_query("insert into `order` (`cust_id`, `order_date`, `order_total`,    
`order_state`, `order_city`, `order_add`, `order_post`)values('$cust_id','$order_date', 
'$order_total', '$order_state', '$order_city','$order_add','$order_post')")
或者,如果您确定它们不是保留字,并且没有空格或其他此类愚蠢的内容,则可以完全删除它们:

$insertQuery=mysql_query("insert into `order`
(cust_id, order_date, order_total, order_state, order_city, order_add, 
order_post)
values('$cust_id','$order_date', 
'$order_total', '$order_state', '$order_city','$order_add','$order_post')")
最后,这假设您在尝试运行查询时确实正确设置了所有变量。如果您尝试插入一个空值,SQL将类似于
insert-into-someTable-values('someValue','')
,这也将生成错误

编辑:要回显数据,请执行以下操作:

echo ("insert into `order`
(cust_id, order_date, order_total, order_state, order_city, order_add, 
order_post)
values('$cust_id','$order_date', 
'$order_total', '$order_state', '$order_city','$order_add','$order_post')");
然后编辑您的问题并添加您看到的输出。这可能会为我们解开谜团。

使用此代码

<?php
include("dbconnection.php");

if ($_SESSION["loggedin"] != "true") {
header("Location:memberlogin.php");
}

$cust_id = $_SESSION["cust_id"];

$result = mysql_query("select customer.*, product.*, order_details.* from customer, product,      
order_details where customer.cust_id=$cust_id and product.pro_id=product.pro_id and    
order_details.order_details_id = order_details.order_details_id")or die(mysql_error());

$row = mysql_fetch_assoc($result);  
?>


使用本指南>>

询问SQL语法问题时,如果您提取生成的SQL并仅发布该SQL,通常会更好(而不是在编程语言中“混淆”您的SQL)。在大多数情况下,您可能自己也会看到错误。我看不出错误消息与提供的代码有何关联!!!您能回显查询以查看您试图在查询中使用的值吗?此外,我在表名周围仍有单引号,我已更正了单引号。这些需要删除或更改为反勾号好的。当你说在数据库中回显查询?或者其他代码?实际上我的第一次尝试没有单引号。在那之后,我包含了这个来回显它,我把它放在运行中,但没有结果。它只是将功能继续到另一个页面。