Updating Records with PHP

The last technique I’ll introduce in this chapter is how to update database records with a PHP script. Doing so requires use of the UPDATE query, and its successful execution can be verified with PHP’s mysql_affected_rows() function.

While the mysql_num_rows() function will return the number of rows generated by a SELECT query, mysql_affected_rows() returns the number of rows affected by an INSERT, UPDATE, or DELETE query. It’s used like so:

$num = mysql_affected_rows($dbc);

The one argument the function takes is the database connection ($dbc), not the results of the previous query ($result).

The following example will be a script that allows registered users to change their password. It’ll demonstrate two important ...

Get PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.