Jump to content

[SOLVED] Help with function


EchoFool

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

Archived

This topic is now archived and is closed to further replies.

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