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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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>>></b></font> <a href=\"showall.php\">Select a RETURN travel </a><b><font color=\"#FF0000\"><<</font></b><br>"; $homepage="<font color=\"#FF0000\"><b>>></b></font> <a href=\"index.php\">Choose a route </a><b><font color=\"#FF0000\"><<</font></b><br><br>"; $changetravel="<font color=\"#FF0000\"><b>>></b></font> <a href=\"bookexpire.php\">CHANGE your travel</a> <b><font color=\"#FF0000\"><<</font></b><br><br>"; $checkout="<font color=\"#FF0000\"><b>>></b></font> <a href=\"book3.php\">CHECKOUT & PAYMENT</a> <b><font color=\"#FF0000\"><<</font></b><br><br>"; $oneway="<font color=\"#FF0000\"><b>>></b></font> <a href=\"showall.php\">Select a 1-WAY travel </a><b><font color=\"#FF0000\"><<</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 |
|
|||
|
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 |
|
|||
|
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' "; |
|
|||
|
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 !!! |
|
|||
|
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 |
|
|||
|
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 |