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
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!

Link to comment
Share on other sites

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.

 

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.