feelay Posted February 12, 2008 Share Posted February 12, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/90751-whats-wrong-in-this-query/ Share on other sites More sharing options...
Caesar Posted February 12, 2008 Share Posted February 12, 2008 Can you paste your query exactly as you have it in your PHP code? Also...please use the code tags. Thaniks. Quote Link to comment https://forums.phpfreaks.com/topic/90751-whats-wrong-in-this-query/#findComment-465201 Share on other sites More sharing options...
feelay Posted February 12, 2008 Author Share Posted February 12, 2008 <?php mysql_query("UPDATE tbl_name SET temphealth = CASE WHEN temphealth + $hp_increase <= maxhp THEN temphealth + $hp_increase ELSE maxhp WHERE temphealth < maxhp"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/90751-whats-wrong-in-this-query/#findComment-465202 Share on other sites More sharing options...
NL_Rosko Posted February 12, 2008 Share Posted February 12, 2008 i guess the statement is missing the END... http://dev.mysql.com/doc/refman/5.0/en/case-statement.html Quote Link to comment https://forums.phpfreaks.com/topic/90751-whats-wrong-in-this-query/#findComment-465230 Share on other sites More sharing options...
feelay Posted February 12, 2008 Author Share Posted February 12, 2008 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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/90751-whats-wrong-in-this-query/#findComment-465258 Share on other sites More sharing options...
NL_Rosko Posted February 12, 2008 Share Posted February 12, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/90751-whats-wrong-in-this-query/#findComment-465267 Share on other sites More sharing options...
feelay Posted February 12, 2008 Author Share Posted February 12, 2008 I've tryed to echo the query (echo query or error). I got the error that i wrote in first post. maxhp is the maximum hp that a character level can have. both maxhp and temphealth is int 11. and yes. CASE is supported by mysql 5 Quote Link to comment https://forums.phpfreaks.com/topic/90751-whats-wrong-in-this-query/#findComment-465271 Share on other sites More sharing options...
NL_Rosko Posted February 12, 2008 Share Posted February 12, 2008 UPDATE tbl_name SET temphealth = CASE WHEN temphealth + $hp_increase <= maxhp THEN temphealth + $hp_increase ELSE maxhp END CASE WHERE temphealth < maxhp Quote Link to comment https://forums.phpfreaks.com/topic/90751-whats-wrong-in-this-query/#findComment-465282 Share on other sites More sharing options...
feelay Posted February 12, 2008 Author Share Posted February 12, 2008 still not working =/ Quote Link to comment https://forums.phpfreaks.com/topic/90751-whats-wrong-in-this-query/#findComment-465299 Share on other sites More sharing options...
NL_Rosko Posted February 12, 2008 Share Posted February 12, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/90751-whats-wrong-in-this-query/#findComment-465308 Share on other sites More sharing options...
feelay Posted February 12, 2008 Author Share Posted February 12, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/90751-whats-wrong-in-this-query/#findComment-465314 Share on other sites More sharing options...
NL_Rosko Posted February 12, 2008 Share Posted February 12, 2008 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 ...); Quote Link to comment https://forums.phpfreaks.com/topic/90751-whats-wrong-in-this-query/#findComment-465324 Share on other sites More sharing options...
feelay Posted February 12, 2008 Author Share Posted February 12, 2008 no idea how this will help.. but here you go.. UPDATE tbl SET temphealth = CASE WHEN temphealth + 0.0833333333333 <= maxhp THEN temphealth + 0.0833333333333 ELSE maxhp END CASE WHERE temphealth > maxhp Quote Link to comment https://forums.phpfreaks.com/topic/90751-whats-wrong-in-this-query/#findComment-465330 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.