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

This is a discussion on Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource within the PHP Language forums, part of the PHP Programming Forums category; Hi people im making an online booking system as a final year project in my university i get this error ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-10-2005
phpguy
 
Posts: n/a
Default Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

Hi people im making an online booking system as a final year project in
my university i get this error which i cannot seem to fix !

Here is my code:

PART 1 ************************************************** *******

#connect to sql
$connect=@mysql_connect("localhost","root","")
or die("Err:Conn");

#database select

$database=@mysql_select_db("times",$connect)
or die("Err:Db");

#create query


//$sql = 'SELECT * FROM `show` ';

$sql = "SELECT * FROM show WHERE from = '$from' AND to = '$to' ";



#execute

$query= @mysql_query($sql,$database) or die('Error ' . mysql_error() .
' in ' . $sql);


PART 2 ************************************************** *******

while ($row = mysql_fetch_array($query))
{

$return="<font color=\"#FF0000\"><b>&gt;&gt;</b></font> <a
href=\"showall.php\">Select a RETURN travel </a><b><font
color=\"#FF0000\">&lt;&lt;</font></b><br>";
$homepage="<font color=\"#FF0000\"><b>&gt;&gt;</b></font> <a
href=\"index.php\">Choose a route </a><b><font
color=\"#FF0000\">&lt;&lt;</font></b><br><br>";
$changetravel="<font color=\"#FF0000\"><b>&gt;&gt;</b></font> <a
href=\"bookexpire.php\">CHANGE your travel</a> <b><font
color=\"#FF0000\">&lt;&lt;</font></b><br><br>";
$checkout="<font color=\"#FF0000\"><b>&gt;&gt;</b></font> <a
href=\"book3.php\">CHECKOUT & PAYMENT</a> <b><font
color=\"#FF0000\">&lt;&lt;</font></b><br><br>";
$oneway="<font color=\"#FF0000\"><b>&gt;&gt;</b></font> <a
href=\"showall.php\">Select a 1-WAY travel </a><b><font
color=\"#FF0000\">&lt;&lt;</font></b><br>";



?>

<br>
<br>
<div align="center">
<table border="1" bordercolordark="#FF0000" cellspacing="0"
cellpadding="0" bordercolorlight="#FF0000" width="731">
<tr>
<td align="center"><font
color="#FF0000"><u><b>TICKET TYPE</b></u></font></td>
<td align="center"><font
color="#FF0000"><u><b>FROM</b></u></font></td>
<td align="center"><font
color="#FF0000"><u><b>TO</b></u></font></td>
<td align="center"><font
color="#FF0000"><u><b>PRICE</b></u></font></td>
<td align="center"><font
color="#FF0000"><u><b>TIME</b></u></font></td>
<td align="center"><font
color="#FF0000"><u><b>DATE</b></u></font></td>
</tr>
<tr>
<td align="center"><?php echo $row["type"];
?></td>
<td align="center"><?php echo $row["from"];
?></td>
<td align="center"><?php echo $row["to"];
?></td>
<td align="center"><?php echo $row["price"]; ?>
GBP</td>
<td align="center"><?php echo $row["time"];
?></td>
<td align="center"><?php echo $row["date"];
?></td>
</tr>
</table>
<table border="1" width="435" bordercolordark="#FFFF00"
bordercolorlight="#FFFF00" cellspacing="0" cellpadding="0">
<tr>





************************************************** *******

So whats wrong in my code ? This error only occurs when i want to
select specific values form the database from a form (the $from,$to)
values if i change my query to display ALL THE RESULTS using

$sql = 'SELECT * FROM `show` ';
itworks perfectly with no errors

please help me !!

cheers

Reply With Quote
  #2 (permalink)  
Old 01-10-2005
phpguy
 
Posts: n/a
Default Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

Also if i place the @ symbol to while ($row =
@mysql_fetch_array($query)) i get a blank page and no result is
displayed, normally results from the database should be displayed with
criteria of departure and arrival. The while loop works great if the
querty chanbages to simply display all the data of the database but
when we become specific and we specify the field from of the database
to be equal to the $from which is the user input from the form we get
errors

cheers

Reply With Quote
  #3 (permalink)  
Old 01-10-2005
claudel@gmail.com
 
Posts: n/a
Default Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

quite simple, and a very often mistake :)

show is a keyword in sql - think of show tables; or show databases; so
changing show to `show` in the actual query will work:
$sql = "SELECT * FROM `show` WHERE from = '$from' AND to = '$to' ";

Reply With Quote
  #4 (permalink)  
Old 01-10-2005
phpguy
 
Posts: n/a
Default Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

thanks but still doesnt work. The error is said to be here


while ($row = mysql_fetch_array($query))

man i have tried everything !!! Also i want to say it works if i
include in the query specific values such as $sql = "SELECT * FROM
`show` WHERE from = 'euston' "; it only messes up when i use variables
!!!

Reply With Quote
  #5 (permalink)  
Old 01-10-2005
Ken Robinson
 
Posts: n/a
Default Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource


phpguy wrote (in part):
> Hi people im making an online booking system as a final year project

in
> my university i get this error which i cannot seem to fix !
>
> Here is my code:
>
> PART 1 ************************************************** *******
>
> #connect to sql
> $connect=@mysql_connect("localhost","root","")
> or die("Err:Conn");
>
> #database select
>
> $database=@mysql_select_db("times",$connect)
> or die("Err:Db");
>
> #create query
>
>
> //$sql = 'SELECT * FROM `show` ';
>
> $sql = "SELECT * FROM show WHERE from = '$from' AND to = '$to' ";
>
>
>
> #execute
>
> $query= @mysql_query($sql,$database) or die('Error ' . mysql_error()

..
> ' in ' . $sql);
>
>
> PART 2 ************************************************** *******
>
> while ($row = mysql_fetch_array($query))
> {
>


[snip]

> So whats wrong in my code ? This error only occurs when i want to
> select specific values form the database from a form (the $from,$to)
> values if i change my query to display ALL THE RESULTS using
>
> $sql = 'SELECT * FROM `show` ';
> itworks perfectly with no errors


Where do the varibles "$from" and "$to" come from? If they are coming
from a submitted form or the URL, you should use $_POST['from'] for
forms or $_GET['from'] for input on the URL.

Also, print out your query just before your "mysql_query" statement.
That should be able to help you find your error.

Ken

Reply With Quote
  #6 (permalink)  
Old 01-10-2005
phpguy
 
Posts: n/a
Default Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

Hello Ken and thanks but still errors.

$from and $to come from a form and thats what i did

$from=$_POST['from'];
$to=$_POST['to'];
$type=$_POST['type'];

also the sql stuff is between the HEADERS of my page while the while
loop is in the body does this have anything to do with it ?

cheers

Reply With Quote
  #7 (permalink)  
Old 01-10-2005
phpguy
 
Posts: n/a
Default Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

guys problem solved !!! thats the query that solved the problem

$sql= "SELECT * FROM `show` WHERE `from` = '$from' AND `to` = '$to'
";

thanks for everytihng

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:09 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0