Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-06-20
4
Medium Priority
?
1,305 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
The viewer will learn how to count occurrences of each item in an array.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

916 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