Jump to content

whats wrong in this query?


feelay

Recommended Posts

Hey!

 

I have a question. Whats wrong with the following query? I ran it in phpmyadmin, and this is what i get:

 

SQL query:

 

UPDATE tbl_name SET temphealth = CASE WHEN temphealth + $hp_increase <= maxhp THEN temphealth + $hp_increase ELSE maxhp WHERE temphealth < maxhp

 

MySQL said: 

 

#1064 - 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 'WHERE temphealth < maxhp' at line 1

 

Any Idea?

Thanks for any help.

 

//Feelay

Link to comment
Share on other sites

That wasn't the error =(

 

This is how the code now looks, but still, it isn't working =/

 

<?php
mysql_query("UPDATE tbl_name SET temphealth = CASE WHEN temphealth + $hp_increase <= maxhp THEN temphealth + $hp_increase ELSE maxhp WHERE temphealth < maxhp END CASE");
?>

Link to comment
Share on other sites

That wasn't the error =(

 

This is how the code now looks, but still, it isn't working =/

 

<?php
mysql_query("UPDATE tbl_name SET temphealth = CASE WHEN temphealth + $hp_increase <= maxhp THEN temphealth + $hp_increase ELSE maxhp WHERE temphealth < maxhp END CASE");
?>

 

did you try basic troubleshooting ? Is case supported under mysql 5.0 ?

where does the value maxhp come from, what is the table layout (int, varchar etc..)

try pasting the sql in phpmyadmin sql window and test/try with fixed values.

echo sql to see the values and paste in sql window

 

 

 

Link to comment
Share on other sites

still not working =/

 

i think the problem is in the values, your statement looks ok

try to echo the sql in your code like this

 

$sql = "";

$res = mysql_query($sql);

echo $sql;

 

past in an sql window if available and run, often gives better error handling

post output complete

 

 

 

Link to comment
Share on other sites

is this what you mean?:

 

Result:

 

#1064 - 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 'CASE WHERE temphealth > maxhp' at line 1 

 

no

run the php code (script), but echo the query as an string as output into your browser. this will show the values that stand for your variables.

under your statement echo/print the complete statement.

 

echo mysql_query("update ...);

 

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.