Hello I have an issue with error handlers in php, im using a login system and only 2 errors work out of 6.
this is the code:
[code]
<?php
if (isset($_POST[‘signup-submit’])) {
require ‘dbh.inc.php’;
$username = $_POST[‘uid’];
$email = $_POST[‘mail’];
$pwd = $_POST[‘pwd’];
$passwordRepeat = $_POST[‘pwdrepeat’];
if (empty($username) || empty($email) || empty($pwd) || empty($passwordRepeat)) {
header(“Location: ../signup.php?error=emptyfields&uid”.$username.”&mail=”.$email);
exit();
}
else if (!filter_var($email, FILTER_VALIDATE_EMAIL) && !preg_match(“/^[a-zA-Z0-9]*$/”, $username)) {
header(“Location: ../signup.php?error=invalidmail&uid”);
exit();
}
else if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
header(“Location: ../signup.php?error=invalidmail”.$username);
exit();
}
else if (!preg_match(“/^[a-zA-Z0-9]*$/”, $username)) {
header(“Location: ../signup.php?error=invaliduid”.$email);
exit();
}
else if ($pwd !==$passwordRepeat) {
header(“Location: ../signup.php?error=passwordcheck”.$email.”username=”.$email);
exit();
}
else {
$sql = “SELECT uidUsers FROM users WHERE uidUsers=?”;
$stmt= mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header(“Location: ../signup.php?error=sqlerror”);
exit();
}
else {
mysqli_stmt_bind_param($stmt, “s”, $username);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
$resultCheck = mysqli_stmt_num_rows($stmt);
if ($resultCheck > 0) {
header(“Location: ../signup.php?error=usertaken”);
exit();
}
else {
$sql = “INSERT INTO users (uidUsers, emailUsers, pwdUsers) VALUES(?, ?,?)”;
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql)) {
header(“Location: ../signup.php?error=sqlerror”);
exit();
}
else {
$hashedPwd= password_hash($password, PASSWORD_DEFAULT);
mysqli_stmt_bind_param($stmt, “sss”, $username, $email, $hashedPwd);
mysqli_stmt_execute($stmt);
header(“Location: ../signup.php?error=success”);
exit();
}
}
}
}
mysqli_stmt_close($stmt);
mysqli_close($conn);
}
else {
header(“Location: ../signup.php”);
exit();
}
————————————————————————————————————————————
and this are the signup.php handlers, first and last work but the others dont
<h3>Signup</h3>
<?php
if (isset($_GET[‘error’])){
if ($_GET[‘error’] == “emptyfields”) {
echo ‘<p class=”signuperror”>Fill in all fields!</p>’;
}
else if ($_GET[‘error’] == “invalidmail”) {
echo ‘<p class=”signuperror”>Fill in all fields!</p>’;
}
else if ($_GET[‘error’] == “invaliduid”) {
echo ‘<p class=”signuperror”>Invalid Username!</p>’;
}
else if ($_GET[‘error’] == “passwordcheck”) {
echo ‘<p class=”signuperror”>Passwords dont match!</p>’;
}
else if ($_GET[‘error’] == “usertaken”) {
echo ‘<p class=”signuperror”>Username is already taken!</p>’;
}
else if ($_GET[‘error’] == “success”) {
echo ‘<p class=”s”>Signup successful!</p>’;
}
}
?>