0

I'm creating a registration form using prepared statement to make my application more secure, but I keep bumping into this error. How can I fix it?

Error:

PHP Fatal error: Uncaught Error: Call to a member function bind_param() on boolean

Code:

if(validate_registration_form($nome, $cognome, $email, $username, $password)){
        $hash = "$2y$10s";
        $salt = "puttingsomesalt";
        $final = $hash . $salt;

        $password = crypt($password, $final);

        $stmt = $connection->prepare("INSERT INTO utenti VALUES(?, ?, ?, ?, ?);");

        $stmt->bind_param('sssss', $nome, $cognome, $email, $username, $password);
        $stmt->execute();
        $stmt->bind_result($nome, $cognome, $email, $username, $password);
        $stmt->store_result();


        if($stmt){
            echo "OOOOK";
        } else{
            echo "NOT OOOOOK";
        }

    } else{
        echo "Not ok bro";
    }
user3783243
  • 5,368
  • 5
  • 22
  • 41
  • `prepare` failed use error reporting to see why. You should define the columns. Also `password_hash` should be used in place of `crypt`. https://www.php.net/manual/en/mysqli.error.php (You currently are using PHP error reporting but mysqli error reporting also is required) – user3783243 Feb 27 '20 at 12:34
  • Column count doesn't match value count at row 1 – Lorenzo Orlando Feb 27 '20 at 12:36
  • 1
    That goes to my second comment, `You should define the columns.` You don't have enough values for the columns this would populate. Likely one of your default columns would be populated with the wrong value (because you want to skip it). `INSERT INTO utenti (column1, column2, etc) VALUES (...)` – user3783243 Feb 27 '20 at 12:38
  • 2
    Use `password_hash()` and `password_verify()` then you can forget about (probably weak salt) and let `password_hash()` automatically generate a strong salt for you – RiggsFolly Feb 27 '20 at 12:48

0 Answers0