Jump to content

spot the syntax error?


blue-genie

Recommended Posts

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>';

}

 

}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>';
            } 
            
         }

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.