SQL PHP HTML ASP JavaScript articles and free scripts to download If you are facing any problem in viewing this page, please tell us
 

MYSQL function to know number of affected records or rows


We 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";}




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
Sections
PHP
JavaScript
ASP
HTML
SQL
Photoshop
Articles SEO
SQL Tutorial List
SQL site Map
Knowledge Management
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.