Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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,301 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 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

Industry Leaders: 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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
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 …
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…

715 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