答案 0 :(得分:1)
选项需要一些值,例如:
<form action="" method="POST">
<select name='choose'>
<option value="mango" >mango</option>
<option value="banana">banana</option>
</select>
</form>
PHP: 将更改设置为()到isset()并添加if-else条件,以处理不同的输入
if( isset( $_POST['choose'] ) ){
if( $_POST['choose'] === "mango" ) {
echo "do the mango";
} elseif( $_POST['choose'] === "banana" ) {
echo "do the banana";
} else {
echo "nothing chosen";
}
}
将其传递给varibale
$chosen_fruit = "none";
// You can also pass the value to a variable
if( isset( $_POST['choose'] ) ){
if( $_POST['choose'] === "mango" ) {
$chosen_fruit = "mango";
} elseif( $_POST['choose'] === "banana" ) {
$chosen_fruit = "banana";
}
}
// here you can use the value of the variable
echo $chosen_fruit;// echo outside the if condition
如果您想了解有关变量范围的更多信息,请查看here
答案 1 :(得分:0)
您必须为每个选项设置值
<form action="" method="POST">
<select name='choose'>
<option value="mango" >mango</option>
<option value="banana">banana</option>
</select>
</form>
if(isset($_POST['choose'])){ //replace is set to isset
echo "Something";
}
答案 2 :(得分:0)
更改为
<option value="mango">mango</option>
<option value="banana">banana</option>
isset
中有空格,所以改变它:
$data="";
if(isset($_POST['choose'])){
$value = $_POST['choose'];
if($value=="fruitValue") {
$data = "do_soemthing";
}
}
$data
访问数据变量。