Jump to content

Recommended Posts

I have a mysql function to check the query before it actually updated.... yet even tho the row was affected the check seems to fail...

 

 

<?php
$Update = mysql_query("UPDATE usertable SET Complete=2 WHERE UserID='{$_SESSION['Current_User']}' AND OtherID='$ID'")
	Or die(mysql_error());
	If(mysql_affected_rows()>1){
                  Echo 'pass';
              }Else{
                  Echo 'fail';
             }
?>

 

I always get Fail being echo'd even though when I check my database it did infact update to "2" for the complete field. Which leads to me being confused as to why the mysql_affected_rows function is not working.

 

Any ideas? Hope you can help! :)

Link to comment
https://forums.phpfreaks.com/topic/109884-solved-help-with-function/
Share on other sites

Oh right i see that makes sense now ! Ok i changed it to >= 1 and it works a treat! Thanks guys ! :D

I just want to point out that your code can be misleading.  It could have executed the query just fine but mysql_affected_rows() could return 0 if the update didn't actually change anything. 

 

If you're just looking to find out if your query executed properly, your script already does that in the first place.  You executed the query and if it failed, your die statement would give you an error.

 

 

Oh right i see that makes sense now ! Ok i changed it to >= 1 and it works a treat! Thanks guys ! :D

I just want to point out that your code can be misleading.  It could have executed the query just fine but mysql_affected_rows() could return 0 if the update didn't actually change anything. 

 

If you're just looking to find out if your query executed properly, your script already does that in the first place.  You executed the query and if it failed, your die statement would give you an error.

 

that is a good point

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.