Cooper94 Posted December 22, 2008 Share Posted December 22, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/137961-search/ Share on other sites More sharing options...
Maq Posted December 22, 2008 Share Posted December 22, 2008 So what's the problem? Do you get errors, what actually happens? First of all NEVER use short tags always start PHP with "<?php". How are you supposed to get $row['name'] when you only SELECT orig? Quote Link to comment https://forums.phpfreaks.com/topic/137961-search/#findComment-721068 Share on other sites More sharing options...
Cooper94 Posted December 22, 2008 Author Share Posted December 22, 2008 Because in the flights database there is a table called orig. I dont get an error it just dosnt show. So when I press submit it just goes to flights.php but no information is showing when I know there is a flight out of KCHS. Thank You Quote Link to comment https://forums.phpfreaks.com/topic/137961-search/#findComment-721076 Share on other sites More sharing options...
Maq Posted December 22, 2008 Share Posted December 22, 2008 Look at this line: This is what you're passing to flights.php (nothing). You want to have this: Quote Link to comment https://forums.phpfreaks.com/topic/137961-search/#findComment-721078 Share on other sites More sharing options...
Cooper94 Posted December 22, 2008 Author Share Posted December 22, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/137961-search/#findComment-721302 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.