Solved

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

Posted on 2008-06-20
4
1,284 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now