Jump to content

Search


Cooper94

Recommended Posts

I am trying to make it so that the form will show all flight from and airport and than when you click submit it will show you the flight from that airport to another. My code:

search.php

<? include 'db.php' ?>
<?php
  // coonnect to database
    $sql = "SELECT orig FROM flights";
    if ($result = mysql_query($sql)) {
      $row = mysql_fetch_assoc($result);
      $row['name']."<br>";
    } else {
    echo "query failed ".mysql_error();
    }
?>
<form method="post" action="flights.php">
<select name="orig">
<option value=""><?echo $row['orig'].""; ?></option>
</select>
<input type="submit" name="orig" value="Submit">
</form>

Flights.php

<?php
include 'db.php';

//Convert posted to variable
$orig = $_POST['orig'];

//Get the goods
$sql = "SELECT * FROM flights WHERE orig = '$orig'";

$result = mysql_query($sql);

//Array the goods
$user_array = mysql_fetch_array($result);

//Convert goods to variables
$orig = $user_array['orig'];



mysql_close($connection);
?>


<center>
      Profile For <?echo $orig;?>!<br>
    
</center> 

I thank you for all the help!

Link to comment
https://forums.phpfreaks.com/topic/137961-search/
Share on other sites

I did the whole code over again and now it only work when you only enter in the arrival. If I try to enter in the departure it will just give me nothing.Here is the code:

Flights.php

<?php
include 'db2.php';

$url_referer = $_SERVER['HTTP_HOST'];

$query = sprintf("SELECT * FROM Domains_v2 WHERE ADDR = '%s' OR ADDR2 = '%s'", $url_referer, $url_referer);

$result = mysql_query($query);

if ( mysql_num_rows($result) > 0 ) {

include 'data.php';

$orig = mysql_real_escape_string($_POST['orig']);
$dest = mysql_real_escape_string($_POST['dest']);


mysql_select_db($database_conn_abrv, $conn_abrv);
$query_flights = "SELECT * FROM flights WHERE orig = '$orig' or dest = '$dest'";
$flights = mysql_query($query_flights, $conn_abrv) or die(mysql_error());
$row_flights = mysql_fetch_assoc($flights);
$totalRows_flights = mysql_num_rows($flights);
}
?>
<center>
      From:<? echo $row_flights['orig']; ?>
      To:<? echo $row_flights['dest']; ?>
</center>

Search.php

<?php include 'db.php' ?>
<?php
  // coonnect to database
    $sql = "SELECT orig,dest FROM flights";
    if ($result = mysql_query($sql)) {
      $row = mysql_fetch_assoc($result);
      $row['orig']."<br>";
    } else {
    echo "query failed ".mysql_error();
    }
?>
<form method="post" action="flights.php">
                    <td height="28" valign="middle" bgcolor="#ffffff" class="bar2">From:
</td>
<input name="orig" type="text" id="orig" value="">
                <tr> 
                  <td height="28" valign="middle" bgcolor="#ffffff" class="bar2">To:</td>
                  <td valign="top"> <input name="dest" type="text" id="dest" value="">

<input type="submit" name="orig" value="Submit">
</form>

Link to comment
https://forums.phpfreaks.com/topic/137961-search/#findComment-721302
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.