kitsibu kitsibu - 3 days ago 5
PHP Question

how would I go about echoing a message at the bottom of my signup page?

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.

Answer

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
Comments