SQL PHP HTML ASP JavaScript articles and free scripts to download

MYSQL function to know number of affected records or rows

We are often interested to know how many records the query affected or updated. The mysql function mysql_affected_rows() will return the number of rows or records affected by any update, insert or delete query. We can test the success of any updating like change of password by a user and accordingly display success or failure message. In the case of password change we will expect that only one record will get update so just after the update sql command we can use mysql_updated_rows() and check whether number of records changed is equal to one or not by using PHP if condition. Like this

$query=mysql_query(“update table_name set password='$password' where userid='$session[userid]'”);

if(mysql_affected_rows() <> 1){echo “There is a problem and your password is not updated”;}
else {echo “Your password updated successfully";}


Google+

More on PHP MySQL functions
Saul hudson25-05-2013
If the password is the same as before affected_rows return 0
smo25-05-2013
yes it will return 0 as there is no change.
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



Join Our Email List
Email:  
For Email Newsletters you can trust

HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer