0

I have a html page that asks the user to enter an email address and then when the user clicks on submit he gets redirected to a link using a php file that I made, but for some reason the php file is not working, it always redirects to the else link my php and my html are below.

<form action="/emailprocess.php">
  Email Address:<br>
  <input id="email" type="text" name="email">
  <br><br>
  <input id="emailaddress" type="submit" class="emailaddress" value="Submit">
</form>
<?php

If($_POST['email'] === "me@apple.com") {
    header("Location: https://www.google.co.uk/");

    } else {
        header("Location: https://google.com/");
    }
?>
Madhur Bhaiya
  • 28,155
  • 10
  • 49
  • 57

3 Answers3

1

You need to set method to post in html code and use if instead of IF,also better to use == instead of ===(since the later will also check the type)

HTML code:

<form action="/emailprocess.php" method="post">
  Email Address:<br>
  <input id="email" type="text" name="email">
  <br><br>
  <input id="emailaddress" type="submit" class="emailaddress" value="Submit">
</form>

PHP code:

<?php
if($_POST['email'] == "me@apple.com") {
   header("Location: https://www.google.co.uk/");
} else {
   header("Location: https://google.com/");
}
?>
flyingfox
  • 13,414
  • 3
  • 24
  • 39
1

Set method=post in your HTML form.

hitesh
  • 11
  • 2
0

replace

<form action="/emailprocess.php">

with

<form action="/emailprocess.php" method="post">

default method attribute is get when you do no insert method attribute in form

so when you submit form this condition if($_POST['email'] == "me@apple.com") never execute

Sally Akl
  • 94
  • 1
  • 6