1 回答
TA贡献1876条经验 获得超5个赞
你没有value在你<option>的属性中给出属性,这就是$db_table当表单被 sumbitted 时没有传入任何内容的原因。而是像下面这样:
<?php
//Declare variables
$db_host = "";
$db_username = "";
$db_pass = "";
$db_name = "";
//$db_table = "";
//Connect to phpMyAdmin
$con=mysqli_connect("$db_host","$db_username","$db_pass","$db_name");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_select_db($con,"$db_name") or die ("No database");
?>
<form action="" name="selection" method="post">
<select project="ConferenceList" id="ConferenceList" name="ConferenceList">
<?php
$result=mysqli_query($con,"select * From conferenceList");
echo "<option> -- Search Conference Name -- </option>";
while($row=mysqli_fetch_array($result))
{
//when form will get submitted whatever will be in value get passed
echo "<option value='.$row[name].'>$row[name]</option>";
}
echo "</select>";
//Close phpMyAdmin
mysqli_close($con); ?>
<input type="submit" name="submit" id="submit" value="Submit" />
</form>
<?php
$db_table = "";
//checking if form is submit
if (isset($_POST["submit"])) {
$db_table = $_POST["ConferenceList"];//will give you value of option selected
echo $db_table;//printing value
}
?>
- 1 回答
- 0 关注
- 152 浏览
添加回答
举报