Skip to content Skip to sidebar Skip to footer

Why I Can't Check My Input And Register My Data Into Database?

It does not show any error output and validate the input field. I don't know what going on here within this code. Hopefully there someone can figure out what happen. Thanks... her

Solution 1:

You'll want to add an else statement to echo your error messages if $error is true.

// if there's no error, continue to signupif( !$error ) {
    $query = "INSERT INTO users(userName,userEmail,userPass) VALUES('$name','$email','$password')";
    $res = mysqli_query($dbcon, $query);

    if ($res) {
        $errTyp = "success";
        $errMSG = "Successfully registered, you may login now";
        unset($name);
        unset($email);
        unset($pass);
    } else {
        $errTyp = "danger";
        $errMSG = "Something went wrong, try again later...";   
    }   

} else {
    // if there's an error, display itecho$nameError . ' ' . $emailError . ' ' . $passError;
}

Perhaps consider using an array to store the errors so it doesn't matter which field has an error, it'll display with easier formatting. For example, in your name validation code:

// basic name validationif (empty($name)) {
    $error = true;
    $errorMsgs[] = "Please enter your full name.";
} elseif (strlen($name) < 3) {
    $error = true;
    $errorMsgs[] = "Name must have at least 3 characters.";
} elseif (!preg_match("/^[a-zA-Z ]+$/",$name)) {
    $error = true;
    $errorMsgs[] = "Name must contain alphabets and space.";
}

// in your if/else statementif(!$error){
    // code here
} else {
    foreach($errorMsgsas$e){
        echo$e . "<br />";
    }
}

Post a Comment for "Why I Can't Check My Input And Register My Data Into Database?"