Viktor Viktor - 1 year ago 61
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



$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);


$nrows = $stmt->affected_rows;

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

Answer Source

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.