-2

这出现在我的页面上方

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

?>

我有一个错误,说你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 'order(cust_id, order_date,order_total, order_state,order_city,order_add,order' 附近使用正确的语法

4

2 回答 2

1

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

$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')");

然后编辑您的问题并添加您看到的输出。这可能会为我们解开谜团。

于 2013-09-01T09:47:06.053 回答
0

使用此代码

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

并使用本指南>> http://www.w3schools.com/php/php_syntax.asp

于 2013-09-01T11:56:56.867 回答