我已经有这个问题 3 天了 :( 我通过 phpmyadmin 创建了一个 3 个数据库,并且我已经将这 3 个数据库放入了一个下拉列表中,我想要的是,当我点击提交时,默认数据库会根据下拉列表的值进行更改列表
这是我想出的代码
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form2" method="post" >
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td colspan="3"><center><strong>Select Default Database</strong></center></td>
</tr>
<tr>
<td><center><select name="db_used">
<?php
$host="localhost";
$username="root";
$password="";
$link = mysql_connect("$host", "$username", "$password")or die("cannot connect");
$result = mysql_list_dbs( $link );
while( $row = mysql_fetch_object( $result ) ){
echo "<option>$row->Database</option>";
}
?>
</select></center></td>
</tr>
<tr>
<td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<?php
$host="localhost";
$username="root";
$password="";
$db_name = "#this depends on the value of the dropdown list";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
?>
任何帮助都非常感谢~~