0

I've tried everything but nothing works, here is my code:

    if(mysqli_connect_error()) {
        die('Connect Error('. mysqli_connect_errno(). ')' . mysqli_connect_error());
    } else {
        $SELECT = "SELECT email From register Where email = ? Limit 1";
        $INSERT = "INSERT Into register(FirstName, LastName, Password, Email, gender) values(? , ? , ? , ? , ?)";

        // Prepare Statement
        $stmt = $conn->prepare($SELECT);
        $stmt-> bind_param("s" , $email);
        $stmt-> execute();
        $stmt-> bind_result($Email);
        $stmt-> store_result();
        $rnum = $stmt->num_rows;

        if($rnum == 0) {
            $stmt-> close();

            $stmt = $conn-> prepare($INSERT);
            $stmt-> bind_param("sssss" , $Firstname , $Lastname , $Email , $password , $gender);
            $stmt-> execute();
                echo "New record inserted sucessfully";
            } else {
                echo "Someone already registered using this email";
            }

            $stmt-> close();
            $conn-> close();
        }
    }

Can somebody help me? It would be a pleasure for somebody's pure help with this 8-day stuck code.

  • Remove the space after `$stmt->` from each occurance. – Ankit Singh Mar 14 '20 at 10:55
  • Do you have any errors (https://stackoverflow.com/questions/17053466/how-to-display-errors-for-my-mysqli-query may help in showing errors). – Nigel Ren Mar 14 '20 at 10:57
  • Is this order of columns exactly like in your database `(FirstName, LastName, Password, Email, gender)`? Because you seem to be inserting in this order `$Firstname , $Lastname , $Email , $password , $gender` – Anurag Srivastava Mar 14 '20 at 10:59
  • Focus on the error message you receive: it clearly states that `$stmt` is a boolean and _not_ a statement as you expect. That means that `$stmt = $conn->prepare(...);` has failed: the documentation clearly states that the method will return `false` if it fails. – arkascha Mar 14 '20 at 13:21

0 Answers0