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 2038
余生分开走
余生分开走 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.

提交回复
热议问题