Page 1 of 1

Reading From two list boxes

Posted: Sun Mar 28, 2004 7:41 am
by eoinmick
I am currently still working on reading the variables but cannot get the code to work...i have just written the 'search' page in html and the 'results' page in php...here is the code..thanks
<html>
<head><title>Bookday & Week Search</title></head>

<body>

<body BGCOLOR="blue">
<div align="center"><center>
<br>
<table border="1" cellspacing="0" width="700">
<tr>
<td align="center" width="700" bgcolor="red"><h1
align="center" h1><em><b>Search by Bookday And Week</b></em></h1>
</td>
</tr>
<tr>
<form action=""bookday&weekresults.php" method="post">
<td align="center" valign="top" bgcolor="green"
height="67"><p align="center">Select Bookday And Week Number from the Search Lists.
<br> Then Press the Search Button</p>
</td>
</tr>
<tr>
<td height="308">&nbsp;

<form action=""bookday&weekresults.php" method="post">
<br>
<center><h3>Select Bookday:</h3>
<br></center>
<center>Bookday;
<select name="bookday">
<option value="sunday">Sunday</option>
<option value="monday">Monday</option>
<option value="tuesday">Tuesday</option>
<option value="wednesday">Wednesday</option>
<option value="thursday">Thursday</option>
<option value="friday">Friday</option>
<option value="saturday">Saturday</option>
</select>

<br><br>

<center>Week Number;
<select name="weekno">
<option value="1">Week 1</option>
<option value="2">Week 2</option>
<option value="3">Week 3</option>
<option value="4">Week 4</option>
<option value="5">Week 5</option>
</select>

<br><br>

<input type=submit value="search">

</center>
</form>

</td>
</tr>

</table>
</center></div>
</body>
</html>

_______________________________

<html>
<head>
<title>Bookday & Week Results</title>
<body bgcolor="blue">
<h1 align="center"><em>Bookday & Week Results</em></font><h1>

<?

//Connect to database

@ $db=mysql_pconnect ("","");

if(!$db)
{
echo "Error:Could not connect";
exit;
}

mysql_select_db("")

//Run Query for search

$query = "select destinationfrom,destinationtill,price,bookday,weekno
from flights,flightprices where flights.flightid=flightprices.flightid
and flights.flyday=flightprices.flyday and flightprices.bookday='$_POST[bookday]'
and flightprices.weekno='$_POST[weekno]';";

//Count Results

$result = mysql_query($query);
$num_results = mysql_num_rows($result);

if ($num_results == 0) {
echo"<p><strong>No Results Found.<br>Please Try Again</strong></p>";
}

else {

echo "<Hr size=5 width=\"90%\"><br>";

echo "<strong>You Searched for: $bookday & $weekno</strong>";

//List Results

for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
}
}
?>

Re: Reading From two list boxes

Posted: Thu Apr 01, 2004 3:52 pm
by Deemo

Code: Select all

<?php
$query = "select destinationfrom,destinationtill,price,bookday,weekno
from flights,flightprices where flights.flightid=flightprices.flightid
and flights.flyday=flightprices.flyday and flightprices.bookday='$_POST[bookday]'
and flightprices.weekno='$_POST[weekno]';"; 
?>
In your Query (above), you say '$_POST[weekno]'. That will give you a mysql error, so instead either extract the $_POST variables or do the following:

Code: Select all

<?php
$query = "select destinationfrom,destinationtill,price,bookday,weekno
from flights,flightprices where flights.flightid=flightprices.flightid
and flights.flyday=flightprices.flyday and flightprices.bookday='{$_POST[bookday]}'
and flightprices.weekno='{$_POST[weekno]}';"; 
?>
the difference is that the post variables have {} around them

Re: Reading From two list boxes

Posted: Fri Apr 02, 2004 2:45 am
by twigletmac
Deemo wrote:In your Query (above), you say '$_POST[weekno]'. That will give you a mysql error
It shouldn't do, unquoted array elements in a double quoted string should be fine. If you use curly brackets then you should quote the element name.

Mac

Posted: Fri Apr 02, 2004 8:16 am
by vigge89
is

Code: Select all

<form action=""bookday&weekresults.php" method="post">
a typo?

should be

Code: Select all

<form action="bookday&weekresults.php" method="post">