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 PHP code follows (since it's a MySQL error, I figured this would be the forum to post it in.):
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.
Code:
[b][COLOR=red]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[/color][/b]
The connection to the database is in an include file and works perfectly. The PHP code follows (since it's a MySQL error, I figured this would be the forum to post it in.):
Code:
$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][COLOR=red]while ($_POST = mysql_fetch_array($result, MYSQL_ASSOC))[/color][/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.