1

I have a newbie question. I am trying to add additional items to the below php file. item_name is working fine and inserts correctly. I added order as another entry, but I get a false success with the below code. It say data entered successfully, but the database does not update. Can someone take a look and point out where my mistake is?

<?php
error_reporting(0);
include("db_config.php");

// array for JSON response
$response = array();

if( !(empty($_POST['item_name'])))
if( !(empty($_POST['order'])))

{
    $item_name=$_POST['item_name'];
    $order=$_POST['order'];

    $result = mysql_query("INSERT INTO myorder(id,item,order) VALUES('','$item_name','$order')");    

    if($result>0){
           $response["success"] = 1;
         }    
     else{
           $response["success"] = 0;
         }
     // echoing JSON response
     echo json_encode($response);
}

?>
Mykola
  • 3,343
  • 6
  • 23
  • 39
user3550653
  • 59
  • 1
  • 10
  • 2
    Start by setting `error_reporting(E_ALL)`, run the query again, then check your server's `error.log` file. After that we can talk about prepared statements. – Darwin von Corax Jan 09 '16 at 18:17
  • 1
    Using http://php.net/manual/en/function.mysql-error.php against your query, would have helped you here. I.e.: `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` – Funk Forty Niner Jan 09 '16 at 18:56
  • I think I have it now. Order is a reserved word. Thanks for the post above that sent me to that list of reserved words. – user3550653 Jan 09 '16 at 19:17

0 Answers0