SQL PHP HTML ASP JavaScript articles and free scripts to download
 
 

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]'”);
Related Tutorial
Number of rows
PHP MySQL functions


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

Discuss this tutorial at forum

List of SQL Tutorials


 
Scripts
PHP
JavaScript
HOME
SQL Tutorial List
SQL (Home)
SQL Commands
AVG
Alter Table
Between
Count
Copy Table
Create Table
Delete
Distinct
Group by
Having
Insert
Inner Join
IN
Left join
Limit
Like
MAX
MIN
Order By
OR AND
Rand
Replace
Rename Table
Select Query
Sum
Union
Update
Where
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.