0

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?

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by nigelburrell
0
$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

0
$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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.