Reading From two list boxes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eoinmick
Forum Newbie
Posts: 22
Joined: Fri Mar 26, 2004 12:30 pm

Reading From two list boxes

Post 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);
}
}
?>
Deemo
Forum Contributor
Posts: 418
Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC

Re: Reading From two list boxes

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Re: Reading From two list boxes

Post 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
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post 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">
Post Reply