如何通过在wamp server.i中使用php来访问数据库中的表。我已经完成了以下代码,但由于某种原因它无法工作。有什么东西可以放入' action ="" ' .it没有给出任何错误但显示相同的页面。我想在下拉菜单中的任何不同条目上显示数据库中的表格并按下搜索按钮..
<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
if(isset($_POST['from']) and isset($_POST['To'])) {
$from = $_POST['from'] ;
$to = $_POST['To'] ;
$table = array($from, $to);
$con=mysqli_connect("localhost");
$mydb=mysql_select_db("homedb");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
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);
?>