PHP form/prepared statements bug

48
February 23, 2019, at 04:10 AM

I am creating a user registration form and I'm having an issue with the prepared statements. If I add an exit(); in the code, the sign up won't lead to anywhere. If I don't add the exit();, the form will display the correct error messages but then dismiss them the second try around.

Also, another (noob) question, how do I implement an error message for an already registered email as well? I added $sql = "SELECT * FROM users WHERE user_name=? AND user_email=?"; and mysqli_stmt_bind_param($stmt, "ss", $name, $email); but I couldn't get the error message to display.

So far for the prepared statements issue:

else {
        $sql = "SELECT * FROM users WHERE user_name=?";
        $stmt = mysqli_stmt_init($con);
        if (!mysqli_stmt_prepare($stmt, $sql)) {
            header("Location: ../index.php?sqlerror");
            exit();
        }
        else {
        mysqli_stmt_bind_param($stmt, "s", $name);
        mysqli_stmt_execute($stmt);
        mysqli_stmt_store_result($stmt);
        $resultCheck = mysqli_stmt_num_rows($stmt);
        if ($resultCheck > 0) {
        array_push($error_array, "Oops! This username is already taken.<br>");
        exit();
        }
Answer 1

you do not need the exit because you already have the header for question registered email: You can use a function num_rows, http://php.net/manual/pt_BR/mysqli-result.num-rows.php

 $mysqli = new mysqli("localhost","root", "", "tables");
 $query = $mysqli->prepare("SELECT * FROM users WHERE user_name=? AND 
  user_email=?");
 $query->execute();
 $query->store_result();
 $rows = $query->num_rows;

and make an if

if($rows>0){
 //message error
}
READ ALSO
Regular expression 301 redirects does not work

Regular expression 301 redirects does not work

I have many pages that were previously in the following format:

54
Google PHP Api Client - I keep getting Error 401: UNAUTHENTICATED

Google PHP Api Client - I keep getting Error 401: UNAUTHENTICATED

I've been struggling with this for hours now, if not days and can't seem to fix it

61
Getting data from nested fields using mongoDB and php driver manager

Getting data from nested fields using mongoDB and php driver manager

I have a document in the following format:

38
How to make it mandatory to check the form&#39;s checkbox?

How to make it mandatory to check the form's checkbox?

I have a form configured with PHP and I'm lost, I do not know how to make it mandatory to check the checkbox that I put in the terms and conditionsI have put the ID but I do not know how to put it in the PHP file

54