0

here check out the code which seems to be showing an error on"//check if input characters are valid the error is of a { bracket" i tried to find the error by removing the bracket or adding another but it won't help. i am new to php so please help me out if you can;

    <?php
if (isset($_POST['submit'])) {
include_once 'dbh.inc.php';

$first = mysqli_real_escape_string($conn, $_POST['first'] );
$last = mysqli_real_escape_string($conn, $_POST['last'] );
$email = mysqli_real_escape_string($conn, $_POST['email'] );
$uid = mysqli_real_escape_string($conn, $_POST['uid'] );
$pwd = mysqli_real_escape_string($conn, $_POST['pwd'] );
//Error Handlers
//Check for empty fields
if (empty($first) || empty($last) || empty($email) || empty($uid) || 
empty($pwd) ){  
header("Location: ../signup.php?signup=empty");
echo "*Please fill in all fields";
exit();
} else{
//Check if input characters are valid
if (!preg_match("/^[a-zA-Z]*$/", $first) || (!preg_match("/^[a-zA-Z]*$/", 
$last)) {
header("Location: ../signup.php?signup=invalid_input_char");
echo "*Please use Uppercase or Lowercase alphabets";
exit();
}else{
//Check if email is valid
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
header("Location: ../signup.php?signup=invalid_email");
echo "*Invalid E-mail address";
exit();
}else{
$sql = "SELECT * FROM users WHERE user_uid= '$uid'";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);

if ($resultCheck > 0) {
header("Location: ../signup.php?signup=useridtaken");
echo "*User Id already taken";
exit();
}
}else{
//Hashed Password
$hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
//Insert the user into the database
$sql = "INSERT INTO users (user_first, user_last, user_uid, user_pwd) VALUES 
('$first', '$last', '$email', '$uid', '$hashedPwd', );";
mysqli_query($conn, $sql);
header("Location: ../signup.php?signup=success");
echo "Congrats your Account has been Created";
exit();

}
}
}

} else{
header("Location: ../signup.php");
exit();
}
  • 1
    FYI, you can't have output and redirect at the same time. It's one or the other. – John Conde Oct 16 '17 at 12:07
  • Your entire `if` clause at line 19 needs an outer set of brackets. For future reference, it helps if you actually include the entire error message in your question. – Ben Hillier Oct 16 '17 at 12:12
  • Use indentation, this will allow you to find where blocks close/open. – chris85 Oct 16 '17 at 12:12
  • can someone plz rewrite the code properly – Paul Heyman Oct 16 '17 at 12:14
  • You have to close the if statement before } else { (line 23). Consider using a PHP IDE if you are a beginner, it will be usefull for you (Aptana, Sublime Text + PHP syntax highlighter, PhpStorm, NetBeans, etc). – Pauloscorps Oct 16 '17 at 12:14
  • @GameBoy errm. Not me! Two people have told you where the error is, and one has posted a link telling you how to diagnose syntax errors. SO is not a coding service. – Ben Hillier Oct 16 '17 at 12:17
  • Incidentally, as far as I'm aware, an `echo` after a `header` statement won't work. This might be useful for debugging, but no more. – Ben Hillier Oct 16 '17 at 12:19
  • i know where the error is but i cant fix it. i tried doing what u said but it still shows the error – Paul Heyman Oct 16 '17 at 12:28

0 Answers0