PHP Search Issue


Posted on 16th Feb 2014 07:03 pm by admin

Hi, I am using the following code to search and return flights from a database. The user searches by inputting a DepID and an ArrID and I want to display only flights that match both DepID and ArrID. However at the moment I am get results only from DepID.. Im sure its something simple but any help appreciated.

Code: <?php
if(isset($_POST['submit'])){
Did you know?Explore Trending and Topic pages for more stories like this.
if(isset($_GET['go'])){
if(preg_match("/^[ a-zA-Z]+/", $_POST['DepID'], $_POST['ArrID'])){
$DepID=$_POST['DepID'];
$ArrID=$_POST['ArrID'];
//connect to the database
$db=mysql_connect ("localhost", "HIDDEN", "HIDDEN") or die ('I cannot connect to the database because: ' . mysql_error());
//-select the database to use
$mydb=mysql_select_db("HIDDEN");
//-query the database table
$sql="SELECT FlightNo, DepID, DepTime, ArrID, ArrTime, Equip FROM routes WHERE DepID LIKE '%" . $DepID . "%' OR ArrID LIKE '%" . $ArrID ."%'";
//-run the query against the mysql query function
$result=mysql_query($sql);
//-create while loop and loop through result set
while($row=mysql_fetch_array($result)){
$FlightNo=$row['FlightNo'];
$DepID=$row['DepID'];
$DepTime=$row['DepTime'];
$ArrID=$row['ArrID'];
$ArrTime=$row['ArrTime'];
$Equip=$row['Equip'];

//-display the result of the array
echo "<ul>n";
echo "<li>" .$FlightNo . " " . $DepID . " " . $DepTime . " " . $ArrID . " " . $ArrTime . " " . $Equip . "</a></li>n";
echo "</ul>";
}
}
else{
echo "<p>Please enter a search query</p>";
}
}
}
?>
No comments posted yet

Your Answer:

Login to answer
86 Like 13 Dislike
Previous forums Next forums
Other forums

Multiple while loops
I have several DB queries that I know should be returning results and aren't. I have a feeling it ha

Upload Code Help
Hi everyone I need some help with a bit of code ive been working with for a while. I am completely s

Creating web pages by php
Hello again,
I was just wondering us there a way to use a php script to create a new web page. I

Calander layout
Hi i know this sounds like a simple question but i cant find the answer to it anywhere i have added

php/xmlrpc class issue
I am working on xml-rpc in php to start with.

I have a class that only has variables defined

Regarding accessing SQL query issued by any user in Oracle 10g
Hi all,
i want to know the queries issued by various users accessing a database...

downloading a file as HTML
Hi.
I'm rather confused with forcing a download. I just want to save dynamic content (from $_SESS

How to generate a random array of integers subject to a certain constraint
I am writing a program that asks the user to enter an integer N and then generates a random array of

Quick Syntax Question
Hi folks,

I'm getting the following error: "unexpected T_LNUMBER". I'm trying to b

Web Host List
Here is a list of web hosts that offer PHP and MySQL. It is no where near a full list, but it is mos

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash