php code is not fetching data from mysql database using wamp server

Posted by john on Stack Overflow See other posts from Stack Overflow or by john
Published on 2014-08-21T20:19:39Z Indexed on 2014/08/22 10:20 UTC
Read the original article Hit count: 181

Filed under:
|
|
|
|

I want to display a table from database in phpMyAdmin by putting the following conditions that in every different options in drop down menu it displays different table from database by pressing the button of search. But it is not doing so.

<p class="h2">Quick Search</p>
    <div class="sb2_opts">
     <p></p>
<form method="post" action="" >
   <p>Enter your source and destination.</p>
   <p>From:</p>
   <select name="from">
     <option value="Islamabad">Islamabad</option>
     <option value="Lahore">Lahore</option>
     <option value="murree">Murree</option>
     <option value="Muzaffarabad">Muzaffarabad</option>
   </select>
<p>To:</p>
   <select name="To">
     <option value="Islamabad">Islamabad</option>
     <option value="Lahore">Lahore</option>
     <option value="murree">Murree</option>
     <option value="Muzaffarabad">Muzaffarabad</option>
   </select>
   <input type="submit" value="search" /> 
</form>
</form> 
</table>

<?php
$con=mysqli_connect("localhost","root","","test"); 
if (mysqli_connect_errno()) 
{ 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
}

if(isset($_POST['from']) and isset($_POST['To'])) {
    $from = $_POST['from'] ;
    $to = $_POST['To'] ;
    $table = array($from, $to);

    switch ($table) {
        case array ("Islamabad", "Lahore") :
           $result = mysqli_query($con,"SELECT * FROM flights");
           echo "</flights>";      //table name is flights
           break;
        case array ("Islamabad", "Murree") :
           $result = mysqli_query($con,"SELECT * FROM isb to murree");
          echo "</isb to murree>";     //table name isb to murree
          ;
          break;
       case array ("Islamabad", "Muzaffarabad") :
           $result = mysqli_query($con,"SELECT * FROM isb to muzz");
           echo "</isb to muzz>";
           break;
       //.....
       //......
       default:
          echo "Your choice is nor valid !!";
    }

}
mysqli_close($con);
?>

© Stack Overflow or respective owner

Related posts about php

Related posts about html