Hi all, I am working on a project where I am creating a travel agency website. At the moment I am trying to get my search engine to get the details and show the result into next page, but nothing is working. can anyone please help? thanks in advance. sorry for my messy code as I AM VERY NEW TO PHP 🙁
Here are my codes for the form on index.php
<form id="search" Name ="sEngine" Method ="POST" ACTION ="search.php" style="background-image:url(images/background.jpg)">
<h2>Search Flights</h2>
<fieldset>
<input type = "radio" name = "type"
id = "return" value = "yes" checked = "checked" />
<label for = "return">Return</label>
<input type = "radio" name = "type"
id = "single" value = "no" />
<label for = "single">Single</label>
</fieldset>
<fieldset id="des">
<ul>
<li>
<label for="depAirport">Deperture airport</label>
<input type="text" id="depAirport" name="depAirport" placeholder="Type destination airport" required autofocus>
</li>
<li>
<label for="arrAirport">Arrival airport</label>
<input type="text" id="arrAirport" name="arrAirport" placeholder="Type arrival airport" required>
</li>
<li>
<label for="dDate">Departure date</label>
<input type="date" id="dDate" name="dDate" required>
</li>
<li>
<label for="rdate">Return date</label>
<input type="date" id="rDate" name="rDate" required>
</li>
</ul>
</fieldset>
<fieldset>
<label for="adult" style="margin-left:10px;">Adult</label>
<input type="number" id="adult" name="adult" min="1" max="20">
<label for="child" style="margin-left:8px;">Child </label>
<input type="number" id="child" name="child" min="0" max="10">
<label for="infants" style="margin-left:8px;">Infants </label>
<input type="number" id="infants" name="infants" min="0" max="10">
</fieldset>
<fieldset>
<label for="clsType" style="margin-left:80px;">Class type</label>
<select id = "myList" name="myList">
<option value = "1" selected="selected">Economy</option>
<option value = "2">Premium Economy</option>
<option value = "3">Business</option>
<option value = "4">First</option>
</select>
</fieldset>
<br/>
<button type= "submit" onclick="myfunc()">Search Now!</button>
</form>
Here are my codes for search.php
<?php
mysql_connect("localhost", "root", "masnobi");mysql_select_db("airline_database");
?>
<?php
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
$name=mysql_real_escape_string($POST['depAirport']); //This value has to be the same as in the HTML form file
$email=mysql_real_escape_string($POST['arrAirport']); //This value has to be the same as in the HTML form file
$sql= "SELECT * from 'flight'
WHERE
(departure_airport ='$depAirport' , arrival_airport = '$arrAirport', departure_date ='$dDate')";
echo "<table id='box' border='1' cellpadding='2' summary='Table holds flight information'>
<tr>
<th>flight_id</th>
<th>flight_no</th>
<th>departure_airport</th>
<th>arrival_airport</th>
<th>departure_date</th>
<th>arrival_date</th>
<th>flight_price</th>
<th>flight_duration</th>
<th>flight_name</th>
</tr>";
while ($row = mysql_fetch_array($result)) {echo "<tr>";
echo "<td>" . $row['flight_id'] . "</td>";
echo "<td>" . $row['flight_no'] . "</td>";
echo "<td>" . $row['departure_airport'] . "</td>";
echo "<td>" . $row['arrival_airport'] . "</td>";
echo "<td>" . $row['departure_date'] . "</td>";
echo "<td>" . $row['arrival_date'] . "</td>";
echo "<td>" . '£' . $row['flight_price'] . "</td>";
echo "<td>" . $row['flight_duration'] . "</td>";
echo "<td>" . $row['flight_name'] . "</td>";
echo "</tr>"; }
?>