Jump to content

PHP Warning help


TEENFRONT

Recommended Posts

Hey

 

Just upgraded servers to latest everything, centos, php, mysql etc.

 

Now im getting this this error (edited ip and dir lisitng)

 

[Wed Jul 09 14:52:28 2008] [error] [client x.x.x.x] PHP Warning:  mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /x/x/x/links/out.php on line 11, referer: http://www.x.co.uk/

 

 

this is my sql

 

$result = mysql_query("SELECT * FROM links WHERE `id` = '$id'") or die(mysql_error()); 

while($r=mysql_fetch_array($result)) {

 

The code above outputs results and the file works fine how i want it to..just appears i have this php warning in my error logs?

 

Any help about whats up?

Link to comment
https://forums.phpfreaks.com/topic/113925-php-warning-help/
Share on other sites

the original syntax is fine.  The query is inside double quotes so the variable should be parsed.

 

i would still put

echo "SELECT * FROM links WHERE `id` = '$id'";

 

on the line just under the $result = line to make sure the query is being populated correctly.

 

This was working fine before the upgrade?

Link to comment
https://forums.phpfreaks.com/topic/113925-php-warning-help/#findComment-585456
Share on other sites

It is likely that code in your while() loop is overwriting the $result variable, because the existing or die() statement on the mysql_query() would have prevented the while() loop from executing the first time if the query failed. Post the code for the whole while() loop.

 

@chriscloyd, putting an or die(mysql_error()) on a mysql_fetch_array() statement is pointless. mysql_fetch_array() does not cause an mysql_error() and mysql_fetch_array() returns a false value whenever there were no rows to be fetched, which is the same thing the while() is testing for.

Link to comment
https://forums.phpfreaks.com/topic/113925-php-warning-help/#findComment-585460
Share on other sites

Hey guys thanks for the help so far.

 

As said, the file works fine. So its not the query code as PFMaBiSmAD said it would die if it were wrong. just these pesky errors in logs files. Would be an issue but we have a very large site and that file is used alot, the log gile is getting hammered :-)

 

@mbeals    -yeah no php warning errors in logs before upgrade.

 

@PFMaBiSmAD - Heres the whole code

 

<?

$id = $_GET['id'];

mysql_connect ---edited out--- 
  mysql_select_db --edited out---


$result = mysql_query("SELECT * FROM links WHERE `id` = '$id'") or die(mysql_error()); 

while($r=mysql_fetch_array($result)) {
$siteurl=$r["siteurl"];
$id = $r["id"];
$out = $r["out"];
$out++;
$day_out = $r["day_out"];
$day_out++;
$sql = "UPDATE links SET `out`='$out', `day_out`='$day_out' WHERE `id`=$id";
$result = mysql_query($sql) or die(mysql_error());
header("Location:$siteurl");
}

?>

 

PFMaBiSmAD if its what you said about overwriting $result, i guess its the second sql query $result in the loop? But surely this shouldnt effect anything? Was all ok before :( should i simply rename the second $result ?

Link to comment
https://forums.phpfreaks.com/topic/113925-php-warning-help/#findComment-585473
Share on other sites

It is likely that the outer query only returns one row (matching the id). This means that when the inner query overwrites the $result variable, the code goes through the loop once and performs the intended actions. The error occurs when the loop goes back for the second iteration.

 

On your previous server/php installation, the error_reporting level was set to prevent warning level errors. This is never a good idea. It is not even a good idea to prevent notice level errors. The error_reporting level should always be set to E_ALL (which it apparently is on your current server) so that problems that occur in your code, like this one, or that information that indicates hacking attempts are occurring get logged in the error log file, but you should set display_errors = Off on a live server to prevent the error messages from being output to the visitor.

 

The coding is incorrect. An UPDATE query only returns a TRUE or FALSE value, which the code is not checking anyway (actually it is by using the or die(...)). Remove the $result = from in front of the mysql_query() that is preforming the UPDATE query. Be careful about re-using loop variables inside of loops.

Link to comment
https://forums.phpfreaks.com/topic/113925-php-warning-help/#findComment-585502
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.