0

The code below states my problem, I wanted the user to be redirected to another page when the gender was set to male and the option was set to child. thank you

<?php
$gender = $age = "";
$age = $_POST['age'];

if($_SERVER["REQUEST_METHOD"]=="POST")
{
if (empty($_POST['gender']))
  {
  $gendererr = "Please fill out your gender...";
  }


if ($age == "SELECT")
  {
  $ageerr = "Please select if you are a child or an adult...";
  }

if ($age === $_POST['child'] && $gender === $_POST['male'])
  {
  header('Location: childfather.html');
  }
}
?>

Here is the HTML:

<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div class="forms-background">
<span class="error"><?php echo $ageerr;?></span>
<br>
<select name="age">
<option name="option">SELECT</option>
<option name="child">Child</option>
<option name="adult">Adult</option>
</select>
<br>
<span class="error"><?php echo $gendererr;?></span><br>
<label>Male</label>
<input type="radio" name="gender" id="male" value="male"><br>
<label>Female</label>
<input type="radio" name="gender" id="female" value="female"><br>
<input type="submit" value="submit" class="submit">
</div>
</form>
www139
  • 4,960
  • 3
  • 31
  • 56

4 Answers4

0

Try

if ($_POST['age']=='child' && $_POST['gender']=='male'){
   header('Location: childfather.html');
}
Nouphal.M
  • 6,304
  • 1
  • 17
  • 28
0

Hi you have to compare the Post variable with a value :

first two line :

$age = $_POST['age'];
$gender= $_POST['gender'];

And your condition :

  if ($age == "child" && $gender == "male")
  {
       header('Location: childfather.html');
  }
Tosx
  • 606
  • 3
  • 8
0
$gender = $_POST['gender'];

if ($age == "child" && $gender == "male")
{
 header('Location:childfather.html');
}
Goikiu
  • 574
  • 3
  • 12
0

You forgot to define the $_POST['gender']

add (on line 3)

$gender= $_POST['gender'];

then change the operator to == in your condition to be

  if ($age == "child" && $gender == "male")
  {
       header('Location: childfather.html');
  }
Yazan Malkawi
  • 501
  • 4
  • 10