Jump to content

SQL Error?


Paws

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/189429-sql-error/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/189429-sql-error/#findComment-999900
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.