Changing Data

You can change data using the mysql_query() function in conjunction with an UPDATE statement.

A successful UPDATE statement does not necessarily change any rows. You need to use a function to call mysql_affected_rows() to discover whether you have changed data in your table. mysql_affected_rows() optionally accepts a link resource; if this is missing, the most recent connection is assumed. This function can be used with any SQL query that can alter data in a table row.

Listing 13.6 builds a script that enables an administrator to change any of the values in the domain column of our sample table.

Listing 13.6. Using mysql_query() to Alter Rows in a Database
 1: <?php 2: $user = "p24_user"; 3: $pass = "cwaffie"; 4: $db = "p24"; 5: ...

Get Sams Teach Yourself PHP in 24 Hours, Third Edition 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.