error in your SQL syntax........near '' at line 1

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: error in your SQL syntax........near '' at line 1

Post by twinedev »

Christopher wrote:I it surprising how often I see PHP code that does not follow basic Structured Programming block structures instead of die().
IMO die() should only be used in the context for routes that should *NOT* occur in production environment, (ie. something with the program isn't operating properly and needs to stop)

A SQL query should be well formatted and checked for data to be used so that even if it returns nothing, the query doesn't actually fail. If something was missing to begin with that needs to go into the query, then the query shouldn't even get executed.

One thing I would suggest adding to Christopher's code if you go that route would be to add the line number to the error message, as it makes it much easier to locate

Code: Select all

$errormsg = "LINE=".__LINE__.", SQL=$XStock_rsUpd, ERROR=" . mysql_error();
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: error in your SQL syntax........near '' at line 1

Post by Christopher »

[quote="twinedev"One thing I would suggest adding to Christopher's code if you go that route would be to add the line number to the error message, as it makes it much easier to locate

Code: Select all

$errormsg = "LINE=".__LINE__.", SQL=$XStock_rsUpd, ERROR=" . mysql_error();
[/quote]
Really excellent suggestion / addition!
(#10850)
Post Reply