In my webpage I'm using the PHP function mysql_fetch_array to check if records are successfully retrieved from the database. If records are returned then I can assign variables with the database fields...

$checkdb = mysql_query("SELECT * FROM products");
if ($info = mysql_fetch_array( $checkdb )) {
     $productName = $info['ProductName'];
}

But how do I check when I change the SQL to an UPDATE or INSERT query if it has worked successfully? I obviously don't want to use the same method as there's no requirement to assign variables from the record fields (as in the example above), but still want to validate if the database UPDATE or INSERT worked correctly. How do I do this?

$result = mysql_query("UPDATE table SET name='joe' WHERE age='21'") 
or die(mysql_error());

For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

http://us.php.net/mysql_query

$result = mysql_query("UPDATE table SET name='joe' WHERE age='21'") 
or die(mysql_error());

For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

http://us.php.net/mysql_query

Ok, great. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.