Solved

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in

Posted on 2008-06-20
4
1,288 Views
Last Modified: 2013-12-12
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 )) {"
<?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);
 
 
 
 
?>

Open in new window

0
Comment
Question by:JPERKS1985
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
kszurek earned 500 total points
ID: 21830806

$result = mysql_query("SELECT * FROM `urls` WHERE `ShortURL` = \"".$URL."\" LIMIT 1");

Open in new window

0
 
LVL 19

Expert Comment

by:Barthax
ID: 21830823
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().
0
 
LVL 19

Expert Comment

by:Barthax
ID: 21830827
Or spot the obvious, like kszurek. ;)
0
 
LVL 29

Expert Comment

by:fibo
ID: 21830830
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]" );
}
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question