Добрый день помогите пожалуйста разобраться почему при регистрации не сохраняет пароль в базу данных mysql ?
код register.php
</head>
<body>
<style>
.help-block{
color:red;
}
</style>
<div class="auth-wrapper">
<div class="auth-content">
<div class="auth-bg">
<span class="r"></span>
<span class="r s"></span>
<span class="r s"></span>
<span class="r"></span>
</div>
<div class="card">
<div class="card-body text-center">
<div class="mb-4">
<i class="feather icon-user-plus auth-icon"></i>
</div>
<h3 class="mb-4">Регистрация</h3>
<form action="<?= htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="input-group mb-1" <?= (!empty($username_err)) ? 'has-error' : ''; ?>">
<input type="username" class="form-control" name="username"value="<?= $username; ?>" placeholder="Никнейм">
</div>
<div class="input-group mb-3" <?= (!empty($email_err)) ? 'has-error' : ''; ?>">
<input type="email" class="form-control" name="email"value="<?= $email; ?>" placeholder="Email">
</div>
<span class="help-block"><?= $email_err; ?></span>
<div class="input-group mb-4" <?= (!empty($password_err)) ? 'has-error' : ''; ?>">
<input type="password" class="form-control" placeholder="Пароль" name="password" placeholder="password" value="<?= $password; ?>">
</div>
<span class="help-block"><?= $password_err; ?></span>
<div class="input-group mb-4" <?= (!empty($confirm_password_err)) ? 'has-error' : ''; ?>">
<input type="password" class="form-control" name="confirm_password" placeholder="Подтверждение пароля" value="<?= $confirm_password; ?>">
</div>
<span class="help-block"><?= $confirm_password_err; ?></span>
<div class="form-group text-left">
<div class="checkbox checkbox-fill d-inline">
<input type="checkbox" name="checkbox-fill-1" id="checkbox-fill-1" checked="">
<label for="checkbox-fill-1" class="cr"> Сохранить пароль</label>
</div>
</div>
<div class="form-group text-left">
<div class="checkbox checkbox-fill d-inline">
<input type="checkbox" name="checkbox-fill-2" id="checkbox-fill-2">
<label for="checkbox-fill-2" class="cr">Подписаться на <a href="#!"> Рассылку</a>.</label>
</div>
</div>
<button class="btn btn-primary shadow-2 mb-4">Регистрация</button>
<p class="mb-0 text-muted">Уже есть аккаунт?<a href="login.php"> Войти</a></p>
</form>
</div>
</div>
</div>
</div>
код php_register.php
<?php
// Define variables and initialize with empty values
$email = $password = $confirm_password = "";
$email_err = $password_err = $confirm_password_err = "";
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST")
{
// Validate email
if(empty(trim($_POST["email"])))
{
$email_err = "Please enter a email.";
}
else
{
// Prepare a select statement
$sql = "SELECT id FROM users WHERE email = ?";
if($stmt = mysqli_prepare($conection_db, $sql))
{
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "s", $param_email);
// Set parameters
$param_email = trim($_POST["email"]);
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt))
{
/* store result */
mysqli_stmt_store_result($stmt);
if(mysqli_stmt_num_rows($stmt) == 1)
{
$email_err = "This email is already taken.";
}
else
{
$email = trim($_POST["email"]);
}
}
else
{
echo "Oops! Something went wrong. Please try again later.";
}
// Close statement
mysqli_stmt_close($stmt);
}
}
// Validate password
if(empty(trim($_POST["password"])))
{
$password_err = "Please enter a password.";
}
elseif
(strlen(trim($_POST["password"])) < 6)
{
$password_err = "Password must have atleast 6 characters.";
}
else
{
$password = trim($_POST["password"]);
}
// Validate confirm password
if(empty(trim($_POST["confirm_password"])))
{
$confirm_password_err = "Please confirm password.";
}
else
{
$confirm_password = trim($_POST["confirm_password"]);
if(empty($password_err) && ($password != $confirm_password))
{
$confirm_password_err = "Password did not match.";
}
}
// Check input errors before inserting in database
if(empty($email_err) && empty($password_err) && empty($confirm_password_err))
{
// Prepare an insert statement
$sql = "INSERT INTO users (email, password) VALUES (?, ?)";
if($stmt = mysqli_prepare($conection_db, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "ss", $param_email, $param_password);
// Set parameters
$param_email = $email;
$param_password = password_hash($password, PASSWORD_DEFAULT); // Creates a password hash
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt))
{
// Redirect to login page
header("location: login.php");
}
else
{
echo "Something went wrong. Please try again later.";
}
// Close statement
mysqli_stmt_close($stmt);
}
}
// Close connection
mysqli_close($conection_db);
}