1

I was just wondering how I would go about getting a message to echo at the bottom of my signup page to let the user know that their email is in use.

$sql_email = "SELECT email FROM user WHERE email='$email'";
    $result_email = mysqli_query($conn, $sql_email);
    $emailcheck = mysqli_num_rows($result_email);

if ($emailcheck > 0) {
        header("Location: ../signup.php?error=email");
        echo("an account with that email is already created, please enter a different email.</a>");
        exit();
    }

this code sends the user to signup.php?error=email where they can sign up again but I would like a message to echo below the sign-up form saying: "an account with that email is already created, please enter a different email." I tried using echo to do this but nothing appears on the page.

kitsibu
  • 45
  • 1
  • 6
  • 2
    Well of course nothing appeared. You're sending a `Location` header that will cause the user's browser to redirect immediately to another page. Nobody is going to see the body text of your redirect page. – r3mainer Dec 01 '16 at 12:14

1 Answers1

1

Remove echo & exit after header location. Because, it will go to sign up page with error as URL parameter. Then, catch it through $_GET and display the error message wherever you want in sign up page.

if ($emailcheck > 0) {
  header("Location: ../signup.php?error=email");
}

signup.php

(Put this code anywhere you want in sign up page.)

if(isset($_GET['error']) && ($_GET['error'] == 'email')){
  echo "<p>an account with that email is already created, please enter a different email</p>";
}

Quick Links

  1. How to set $_GET variable
  2. $_GET : PHP Manual
Community
  • 1
  • 1
Nana Partykar
  • 10,556
  • 10
  • 48
  • 77