blue-genie Posted May 28, 2010 Share Posted May 28, 2010 i keep getting the problem message. function update(){ $result2 = mysql_query("UPDATE gamedetails SET gameName = '".$newGameName."', startDate = '".$newStart."', endDate = '".$newEnd."', turnsPerDay = '".$newTurnsPerDay."', numAttempts = '".$newNumAttempts."', gameIsActive = '".$newActiveState."' WHERE gameID = ".$editGameID); if(mysql_affected_rows() <> 1){ echo "There is a problem with update"; } else { echo '<?xml version="1.0"?>'; echo '<dataxml>'; echo '<row type="success">'; echo "<resMsg>Updated.</resMsg>"; echo "</row>"; echo '</dataxml>'; } } Quote Link to comment https://forums.phpfreaks.com/topic/203187-spot-the-syntax-error/ Share on other sites More sharing options...
phpchamps Posted May 28, 2010 Share Posted May 28, 2010 print the query run it through phpmyadmin or any other mysql GUI tool.. and see how many rows its affecting.. Quote Link to comment https://forums.phpfreaks.com/topic/203187-spot-the-syntax-error/#findComment-1064570 Share on other sites More sharing options...
blue-genie Posted May 28, 2010 Author Share Posted May 28, 2010 it is affecting 0 rows but i'm trying to figure out why. the variables exist (have echo'd to check) and if i hard code the values in there they work. Quote Link to comment https://forums.phpfreaks.com/topic/203187-spot-the-syntax-error/#findComment-1064575 Share on other sites More sharing options...
phpchamps Posted May 28, 2010 Share Posted May 28, 2010 as query is returning 0 your first condition will always satisfy and it will display the error. as 0 is not equal to 1. if you are not modifying any values then mysql will r return 0 rows updated..... so, if you update any of the value and run the query then it will return you updated rows... So, in short. mysql will return you how many rows have been updated but in your case none of the row is updated so it will reutrn you 0. To solve it you will have to change your condition and if it returns you 0 you will not check generate xml.. is its 1 or more than 1 then only generate xml Quote Link to comment https://forums.phpfreaks.com/topic/203187-spot-the-syntax-error/#findComment-1064576 Share on other sites More sharing options...
blue-genie Posted May 28, 2010 Author Share Posted May 28, 2010 Hi phpchamp. thanks for that. makes sense but why is the update not actually happening? anything jump out at you?i'm not getting any errors but the update is just not happening with the variables i've passed through. Quote Link to comment https://forums.phpfreaks.com/topic/203187-spot-the-syntax-error/#findComment-1064581 Share on other sites More sharing options...
Adam Posted May 28, 2010 Share Posted May 28, 2010 You need to look at the where clause as to why this isn't working. When you printed out the SQL as phpchamps suggested, was the game ID a valid ID within the database? -- If you run select * from gamedetails where gameID = <<that ID>>;, does this return the correct data? Quote Link to comment https://forums.phpfreaks.com/topic/203187-spot-the-syntax-error/#findComment-1064588 Share on other sites More sharing options...
phpchamps Posted May 28, 2010 Share Posted May 28, 2010 your update query is firing successfully. change the variable value and then try if you fire a update query and value which you are updating which is as its in the database then also your update query will fire successfully but result will be 0 because there is no change in the values you passed to query and values which is already available in mysql record.... try to modify the values which you are sending in query.. Quote Link to comment https://forums.phpfreaks.com/topic/203187-spot-the-syntax-error/#findComment-1064601 Share on other sites More sharing options...
Andy-H Posted May 28, 2010 Share Posted May 28, 2010 function update(){ $result2 = mysql_query("UPDATE gamedetails SET gameName = '".$newGameName."', startDate = '".$newStart."', endDate = '".$newEnd."', turnsPerDay = '".$newTurnsPerDay."', numAttempts = '".$newNumAttempts."', gameIsActive = '".$newActiveState."' WHERE gameID = ".$editGameID." LIMIT 1")or trigger_error(mysql_error(), E_USER_ERROR); if(mysql_affected_rows() <> 1){ echo "There is a problem with update"; } else { echo '<?xml version="1.0"?>'; echo '<dataxml>'; echo '<row type="success">'; echo "<resMsg>Updated.</resMsg>"; echo "</row>"; echo '</dataxml>'; } } Quote Link to comment https://forums.phpfreaks.com/topic/203187-spot-the-syntax-error/#findComment-1064613 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.