Paws Posted January 22, 2010 Share Posted January 22, 2010 Hey, I am having trouble with the following sql query... $query = mysql_query("INSERT INTO `orders` (`order_status`,`productcode` ,`dispatch_date` ,`customer_id`) VALUES ('Ordered', '$item', '$date', '$email'") or trigger_error(mysql_error()); I am getting the error... Notice: 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 '' at line 1 in /home/spadean1/public_html/john/order.php on line 46 Any help appreciated. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/189429-sql-error/ Share on other sites More sharing options...
Adam Posted January 22, 2010 Share Posted January 22, 2010 You're missing a right bracket after the values. Quote Link to comment https://forums.phpfreaks.com/topic/189429-sql-error/#findComment-999897 Share on other sites More sharing options...
Psycho Posted January 22, 2010 Share Posted January 22, 2010 You should get in the habit of creating your query as a string variable. Then when there is a problem you can echo the query to the page or log it somewhere so you can debug the error. It is not always apparent what the error is when looking at how the query is built. It is much more apparent when looking at the final code of the query. Like this: $query = "INSERT INTO `orders` (`order_status`, `productcode`, `dispatch_date`, `customer_id`) VALUES ('Ordered', '$item', '$date', '$email')"; $result = mysql_query($query) or trigger_error("Query:<br />$query<br />Error:<br />".mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/189429-sql-error/#findComment-999900 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.