【发布时间】:2018-03-06 05:35:50
【问题描述】:
我正在尝试复制以下内容:
php if statement html option value 并按照建议的指示进行操作:
为您的选择命名。
<select name="selectedValue">
<option value="Newest">Newest</option>
<option value="Best Sellers">Best Sellers</option>
<option value="Alphabetical">Alphabetical</option>
</select>
在php中
Example:
switch($_POST['selectedValue']) {
case 'Newest':
// do Something for Newest
break;
case 'Best Sellers':
// do Something for Best seller
break;
case 'Alphabetical':
// do Something for Alphabetical
break;
default:
// Something went wrong or form has been tampered.
}
但是,我收到以下错误:
注意:未定义索引:第 7 行 C:\xampp\trial.php 中的 selectedValue
请帮忙
【问题讨论】:
-
请确认是否选择了任何选项。
-
一加载页面就会出现错误,即使我选择了一个选项,也没有任何变化。
-
$_POST仅在您提交表单时填写。当您第一次加载页面时,它不会有任何值。在尝试使用参数之前,您需要检查表单是否已提交。 -
怎么样?我应该添加提交按钮吗?