You have an error in your SQL syntax; near 'order(cust_id, order_date,order_total, order_state,order_city,order_add,order' at line 1

后端 未结 2 2039
余生分开走
余生分开走 2021-01-29 12:20

This appears above my page



        
相关标签:
2条回答
  • 2021-01-29 13:19

    You are using single quotes around column names:

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

    Try this instead:

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

    Or you can remove them completely if you are sure they aren't reserved words and they don't have spaces or other such silly things in them:

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

    Lastly, this assumes that you do indeed have all the variables set correctly at the time you try to run the query. If you try to insert a value that is empty, the SQL will end up like insert into someTable values ('someValue','') which will generate an error as well.

    Edit: To echo out the data do this:

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

    And then edit your question and add the output you see. This will probably solve the riddle for us.

    0 讨论(0)
  • 2021-01-29 13:21

    Use this code

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

    And use this guide >> http://www.w3schools.com/php/php_syntax.asp

    0 讨论(0)
提交回复
热议问题