0

Hello I'm Pretty New To PHP I'm trying to Make an Script if the user selects an Radio Option It Will Redirect them to an site.

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>
Jonas
  • 121,568
  • 97
  • 310
  • 388
  • you have no value; you're relying on an id which also doesn't match `Blue` or matching name attribute. and if full php, is missing a brace – Funk Forty Niner Sep 28 '16 at 17:06
  • you need `value="red"` and `value="blue"` on your radio inputs. `id` is for referencing via CSS stylesheet, and/or Javascript. – Duane Lortie Sep 28 '16 at 17:11

1 Answers1

1

You are missing values for the radio button and then alone you can check whether the value posted is equal to the value or not.

You HTML need to be altered like this

<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>

Since i have provided a name for the submit button i can check with that in PHP page.

badge.php

<?php
if(isset($_POST['save']))
{
if (isset($_POST["badge"]) ) {
if($_POST["badge"]=="Blue"){
header("Location: /form-error.shtm");
}
}
}
?>
Naresh Kumar P
  • 4,127
  • 2
  • 16
  • 33
  • I get an error when i submit a option. Parse error: syntax error, unexpected end of file in /home/whmcucc/public_html/lynxkik.ml/test/badge.php on line 9 –  Sep 28 '16 at 17:37
  • One `}` left and now i have updated it in my answer – Naresh Kumar P Sep 28 '16 at 17:38