How can the mysql_affected_rows function be used to determine if a database update or insert operation was successful in PHP?
To determine if a database update or insert operation was successful in PHP, you can use the mysql_affected_rows function. This function returns the number of affected rows by the last INSERT, UPDATE, or DELETE query. By checking if the returned value is greater than 0, you can determine if the operation was successful.
// Perform database update or insert operation
$query = "UPDATE table_name SET column_name = 'new_value' WHERE condition";
$result = mysql_query($query);
// Check if the operation was successful
if (mysql_affected_rows() > 0) {
echo "Operation was successful";
} else {
echo "Operation was not successful";
}