JPERKS1985
asked on
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
I receive the following error when trying to run my script,
"Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in html/geturl.php on line 20"
It seems to be this line "while($row = mysql_fetch_array( $result )) {"
"Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in html/geturl.php on line 20"
It seems to be this line "while($row = mysql_fetch_array( $result )) {"
<?php
$URL = $_GET["URL"];
$con = mysql_connect("****","****","****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("urlshortener1986", $con);
$result = mysql_query("SELECT * FROM `urls` WHERE `ShortURL` = ".$URL." LIMIT 1");
while($row = mysql_fetch_array( $result )) {
echo '<meta http-equiv="refresh" content="5;url='.$row['URL'].'">';
}
mysql_close($con);
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In all likelihood your mysql_query has returned an error & not a MySQL resource. Check what the content of the $result is prior to attempting to use it - the $result will contain false on an error & you can retrieve the error details through mysql_errno() and mysql_error().
Or spot the obvious, like kszurek. ;)
Line 16: check if you have results. if there is no anwers, then mysql_fetch_arry cannt work and issues the diagnostice you have got
if (!$result) {
die('Invalid query: ' . mysql_error()."<br>No answer when looking at [$URL]" );
}
if (!$result) {
die('Invalid query: ' . mysql_error()."<br>No answer when looking at [$URL]" );
}