Viktor Viktor - 6 months ago 10
PHP Question

PHP Can't find what is wrong with my code (Registration)

Im trying to create a registration form with prepared statements, hashing of passwords, I keep getting "something went wrong message" that i supplied in

else
statement.

if(isset($_POST['save'])){

$username = $_POST["username"];
$password = password_hash($_POST["password"], PASSWORD_BCRYPT);
$email = $_POST["email"];

$stmt = $mysqli->prepare("INSERT INTO users (username, password, email) VALUES (?, ?, ?)");
$stmt->bind_param("sss",$username, $password, $email);

$stmt->execute();

$nrows = $stmt->affected_rows;

if($nrows == 1){
header("Location: http://localhost/test2/Login.php");}
else{
echo "<script type='text/javascript'>alert('Something went wrong!')</script>";}
}

Answer

Your password field in db is CHAR(40). but the statement

password_hash($_POST["password"], PASSWORD_BCRYPT);

is giving 60 char.. That must be a problem.