2016-09-28 97 views
0

你好我很漂亮新到PHP我试图做一个脚本,如果用户选择一个无线电选项,它会重定向到一个网站。PHP如何检查答案时重定向收音机?

PHP:

if (isset($_POST["badge"])) { 
if($_POST["badge"]==="Blue"){ 

header("Location: /form-error.shtm"); 
} 

HTML:单选按钮

<form action="badge.php" method="post"> 
<p> 
    <input class="with-gap" name="group1" type="radio" id="red" /> 
    <label for="red">Red</label> 
</p> 
<p> 
    <input class="with-gap" name="group1" type="radio" id="blue" /> 
    <label for="blue">Blue</label> 

        <div class="col offset-s7 s5"> 
         <button class="btn waves-effect waves-light red darken-1" type="submit">Submit 
          <i class="mdi-content-send right white-text"></i> 
</form> 
+0

你有没有价值;你所依靠的ID也不符合'Blue'或匹配的名称属性。如果完整的php,缺少一个大括号 –

+0

你的无线电输入需要'value =“red”'和'value =“blue”'。 'id'用于通过CSS样式表和/或Javascript进行引用。 –

回答

1

你缺少值,然后独自你可以检查张贴的值是否等于值与否。

您HTML需要改变这样

<form action="badge.php" method="post"> 
<p> 
<input class="with-gap" value="Red" name="group1" type="radio" id="red" /> 
<label for="red">Red</label> 
</p> 
<p> 
<input class="with-gap" value="Blue" name="group1" type="radio" id="blue" /> 
<label for="blue">Blue</label> 

<div class="col offset-s7 s5"> 
<button class="btn waves-effect waves-light red darken-1" name="save" type="submit">Submit 
<i class="mdi-content-send right white-text"></i> 

,因为我已经规定的提交按钮,我可以在PHP页面查询的名称。

badge.php

<?php 
if(isset($_POST['save'])) 
{ 
if (isset($_POST["badge"])) { 
if($_POST["badge"]=="Blue"){ 
header("Location: /form-error.shtm"); 
} 
} 
} 
?> 
+0

我提交选项时出现错误。解析错误:语法错误,第9行的/home/whmcucc/public_html/lynxkik.ml/test/badge.php中的文件意外结束 – Rab

+0

一个'}'离开了,现在我在回答中更新了它 –