Jump to content

Unknown Mysql syntax error...


Seaholme

Recommended Posts

Hey all,

 

I keep getting this 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 2

 

When I use the script below. I'm finding it a bit confusing because everything about it continues to work, it's just it gives me an error. When the script runs, the outcome is

 

"Success! Your dog now looks far more energetic!

Looks like this food is all used up."

 

Followed by the error, which cuts the remainder of the page off. Does anybody know why it's doing this?

 

	$dogyay = $_POST['dogid'];	

$checkenergy = "SELECT energy FROM dogs WHERE id=$dogyay"; 	 
$energylevel = mysql_query($checkenergy) or die(mysql_error());
$row = mysql_fetch_array($energylevel) or die(mysql_error());

if($row['energy'] >= 100)
{ echo "<b>Oops!</b> Looks like your dog is full right now...";}

else{ 	

echo "<b>Success! Your dog now looks far more energetic!</b><br><br>";

$sql11="UPDATE dogs SET energy=energy + 50 WHERE id=$dogyay";
$result11=mysql_query($sql11);

$sql12="UPDATE items SET uses = uses - 1 WHERE itemid=$id";
$result12=mysql_query($sql12);

$checkuses = "SELECT uses FROM items WHERE itemid=$id"; 	 
$useslevel = mysql_query($checkuses) or die(mysql_error());
$row = mysql_fetch_array($useslevel) or die(mysql_error());

if($row['uses'] == 0)
{ echo "Looks like this food is all used up.<bR><br>";

mysql_query("DELETE FROM items WHERE itemid='$id'") 
or die(mysql_error());}

 

Thanks !

Link to comment
https://forums.phpfreaks.com/topic/212376-unknown-mysql-syntax-error/
Share on other sites

Ah elsewhere in the script, it comes from the URL as a $_GET['id'] type thing. I've checked all of the variables by echoing them out and they do -- also the script itself functions perfectly, which it wouldn't do if any of the variables were wrong. That's kinda why I'm very confused!

Yep, it does. It's a number to say which item it is.

 

I've been thinking about it and I was wondering, is it possible that because one of those lines deletes the item from the database that that is giving the error?

What do you mean? Variables used within a query will not be unset. So no it shouldn't affect the $id variable

 

To find out which query is causing the error . Change the or die(myql_error()); bits to include your queries, eg

	$checkenergy = "SELECT energy FROM dogs WHERE id=$dogyay"; 	 
$energylevel = mysql_query($checkenergy) or die($checkenergy . '<br />' . mysql_error());

 

That way you will know which query the error refers to and it'll stop use from asking silly questions.

 

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.