mastercjb Posted October 28, 2009 Share Posted October 28, 2009 I have a code for my game where people can donate cash and crystals to there gang. However I get this error: QUERY ERROR: 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 Query was INSERT INTO gangevents VALUES('',13,unix_timestamp(),"Homer donated $0 and/or 5 crystals to the Gang."); It will still put the cash or crystals into the tables in my database, but I dont see why I am getting this error... Here is the code where it puts the info into the tables. Do you guys see anything wrong? { $db->query("UPDATE users SET money=money-{$_POST['money']},crystals=crystals-{$_POST['crystals']} WHERE userid=$userid"); $db->query("UPDATE gangs SET gangMONEY=gangMONEY+{$_POST['money']},gangCRYSTALS=gangCRYSTALS+{$_POST['crystals']} WHERE gangID={$gangdata['gangID']}"); $db->query("INSERT INTO gangevents VALUES('',{$gangdata['gangID']},unix_timestamp(),\"<a href='viewuser.php?u=$userid'>{$ir['username']}</a> donated \${$_POST['money']} and/or {$_POST['crystals']} crystals to the Gang.\");"); print "You donated \${$_POST['money']} and/or {$_POST['crystals']} crystals to the Gang."; } Quote Link to comment https://forums.phpfreaks.com/topic/179326-query-error/ Share on other sites More sharing options...
monkeybidz Posted October 28, 2009 Share Posted October 28, 2009 Looks like your just leaving an empty VALUE space: Try changing from: $db->query("INSERT INTO gangevents VALUES('',{$gangdata['gangID']},unix_timestamp(),\"<a href='viewuser.php?u=$ To $db->query("INSERT INTO gangevents VALUES({$gangdata['gangID']},unix_timestamp(),\"<a href='viewuser.php?u=$ Quote Link to comment https://forums.phpfreaks.com/topic/179326-query-error/#findComment-946158 Share on other sites More sharing options...
mastercjb Posted October 28, 2009 Author Share Posted October 28, 2009 Tried that there is no change, im still getting the error. Quote Link to comment https://forums.phpfreaks.com/topic/179326-query-error/#findComment-946176 Share on other sites More sharing options...
mastercjb Posted October 29, 2009 Author Share Posted October 29, 2009 Can anyone help me? Quote Link to comment https://forums.phpfreaks.com/topic/179326-query-error/#findComment-946768 Share on other sites More sharing options...
PFMaBiSmAd Posted October 29, 2009 Share Posted October 29, 2009 How exactly are you getting and displaying that query error and the query? The error message is typical of a numeric value being empty on the right-side of a comparison (such as userid= or gangID= ) but the query being printed is valid (except for possibly needing a space between VALUES and the ( ). I'll guess that the actual query error is coming from a previous query than the one that is being printed after the error message. Quote Link to comment https://forums.phpfreaks.com/topic/179326-query-error/#findComment-946791 Share on other sites More sharing options...
DavidAM Posted October 29, 2009 Share Posted October 29, 2009 What is the layout of the gangevents table. Is the first column an INTEGER AUTO_INCREMENT column? If so, I think you have to specify NULL not an empty string. OR list the column names and don't provide any value for the auto_increment: INSERT INTO gangevents (GangID, EventDateTime, EventDescription) VALUES ({$gangdata['gangID']}, unix_timestamp(), \"<a href='viewuser.php?u=$userid'>{$ir['username']}</a> donated \${$_POST['money']} and/or {$_POST['crystals']} crystals to the Gang.\") QUERY ERROR: 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 Usually a query error shows some part of the query starting near where the server thinks the error is. In the message you posted that would appear between the single quotes near '' at line 1. I don't remember ever seeing this empty (well maybe once or twice). Also, since your query (and possibly the error message) has some HTML markup in it, when you get the error, you may want to use the "View Source" capability of the browser, find the error, and see what else is being sent to the browser that is being interpreted instead of being displayed. Quote Link to comment https://forums.phpfreaks.com/topic/179326-query-error/#findComment-946806 Share on other sites More sharing options...
fenway Posted October 31, 2009 Share Posted October 31, 2009 If you post the actual queries, that would help too -- not php code. Quote Link to comment https://forums.phpfreaks.com/topic/179326-query-error/#findComment-948413 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.