Solved

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

Posted on 2008-06-20
4
1,299 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
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 look for a specific file type in a local or remote server directory using PHP.

630 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