Jump to content

QUERY ERROR?


mastercjb

Recommended Posts

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.";
}

Link to comment
Share on other sites

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=$

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.