First off, let me state that I have read the FAQ about this error, and have tried all the fixes, with no success. If anyone can give me a hand with this I'd be grateful.
I've got some PHP web pages that connect to a MySQL database. I've got a query that deletes a record from a database, but it always generates the following error:
The connection to the database is in an include file and works perfectly.
The exact error is:
[B]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /usr/local/psa/home/vhosts/XXX.com/httpdocs/PROJECT1/process_authors.php on line 39[/B]
The connection to the database is in an include file and works perfectly. The PHP code follows:
$result = mysql_query("SELECT * FROM MYAUTHORS where authorid = '$record_key'") or die("Error:.mysql_error());");
$rows=mysql_affected_rows();
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
} else {
[B]while ($_POST = mysql_fetch_array($result, MYSQL_ASSOC))[/B] {
$id = $_POST['id'];
$authorid = $_POST['authorid'];
$lname = $_POST['lname'];
$fname = $_POST['fname'];
$query ="DELETE from MYAUTHORS where authorid = '$record_key'";
$result = mysql_query($query);
$rows=mysql_affected_rows(); // returns number of rows produced by query.
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
} else {
if ($rows === 0) {
echo "Record not found.<br>";
}
}
}
}
The code hilighted in red is what's generating the error message. The problem is that the code seems to work perfectly, as the correct record is deleted from the database, but the error message is still generated. If I put an at sign "@" infront of the mysql_fetch_array, it suppressed the error message. That's fine, but I'd really like to know what's causing the message and eliminate the cause. Any help would be greatly appreciated.