amd*_*dvb 0 html php forms radio-button
有人能指出我为什么以下不起作用?即使我选择不同的单选按钮,它也只会重定向到第一个位置.
PHP:
if (isset($_POST['submit'])) {
if (!empty($_POST['electronics'])) {
if ($_POST['electronics'] = "camera") {
header("location: camera.php");
exit();
}
if ($_POST['electronics'] = "cell") {
header("location: cellphones.php");
exit();
}
if ($_POST['electronics'] = "cable") {
header("location: cables.php");
exit();
}
if ($_POST['electronics'] = "tv") {
header("location: tv.php");
exit();
}
}
...
Run Code Online (Sandbox Code Playgroud)
HTML:
<form action="" method="post">
<input type="radio" name="electronics" value="cell"/>
<input type="radio" name="electronics" value="camera"/>
<input type="radio" name="electronics" value="cable"/>
<input type="radio" name="electronics" value="tv"/>
<input type="submit" name="submit">
</form>
Run Code Online (Sandbox Code Playgroud)
您必须使用比较运算符==而不是=
if (isset($_POST['submit'])) {
if (!empty($_POST['electronics'])) {
if ($_POST['electronics'] == "camera") {
header("location: camera.php");
}
else if ($_POST['electronics'] == "cell") {
header("location: cellphones.php");
}
else if ($_POST['electronics'] == "cable") {
header("location: cables.php");
}
else if ($_POST['electronics'] == "tv") {
header("location: tv.php");
}
}
...
Run Code Online (Sandbox Code Playgroud)
此外,exit()由于您已经重定向到另一个页面,因此也是多余的.
| 归档时间: |
|
| 查看次数: |
115 次 |
| 最近记录: |