简体   繁体   中英

Blank white page on form submit

Hi there hoping someone can help.

I am trying on a project and this would be a signup page, When all inputs are filled in it works and INSERTS and takes to new page home.php BUT when doing empty field checks or email in use check all I get is a white page, error reporting is on but no errors showing.

Thanks.

if (isset($_POST["signup_submit"])) {

$email = mysqli_real_escape_string($conn, $_POST['email']);
$pwd = mysqli_real_escape_string($conn, $_POST["pwd"]);
$pwdRepeat = mysqli_real_escape_string($conn, $_POST["pwdRepeat"]);
$message = "";

if(empty($email) || empty($pwd) || empty($pwdRepeat)) {
  $message = "All fields are required!";
exit();
}

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
 $message = "Please use a valid email!";
 exit();
}

if ($pwd !== $pwdRepeat) {
  $message = "Passwords do not match";
  exit();
}

$sql = "SELECT email FROM Accounts WHERE email = ?;"; 
$stmt = mysqli_stmt_init($conn);

if (!mysqli_stmt_prepare($stmt, $sql)) {
  $message = "stmt failed!";
  exit();
}
  
mysqli_stmt_bind_param($stmt, "s", $email);
mysqli_stmt_execute($stmt);
  
  $result = mysqli_stmt_get_result($stmt);
  $row = mysqli_num_rows($result);
  
if($row !== 0){
$message = "Email already used!";
exit();
}else{
    
$sql = "INSERT INTO Accounts (email, password, account_reg) VALUES (?, ?, ?);";
$stmt = mysqli_stmt_init($conn);

if (!mysqli_stmt_prepare($stmt, $sql)) {
$message = "stmt failed!";
exit();
}

$hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);

mysqli_stmt_bind_param($stmt, "sss", $email, $hashedPwd, $time);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
header("location: home.php");
exit();

}
  
}

Don't call the exit(); method. It simply kills the process and this is the reason why you are seeing a blank page. If you want to display the error message and then kill the process use die('Error message'); instead.

You are setting $message to an error string, but you are not displaying it, ie echo $message;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM