<?php
session_start();
if(isset($_POST['chPasswordSubmit'])) {
include('dbh.inc.php');
$oPassword = mysqli_real_escape_string($conn, $_POST['oldPassword']);
$nPassword1 = mysqli_real_escape_string($conn, $_POST['nPassword1']);
$nPassword2 = mysqli_real_escape_string($conn, $_POST['nPassword2']);
$chEmail = $_SESSION['u_email'];
if (empty($oPassword) || empty($nPassword1) || empty($nPassword2)) {
echo "Prosim vyplňte všetky polia";
exit();
} else {
if (strlen($nPassword1) < 8) {
echo "heslo musí mať aspoň 8 znakov";
} else {
if ($_POST['nPassword1'] !== $_POST['nPassword2']) {
echo "heslá sa musia zhodovať";
} else {
$sql = "SELECT user_password FROM users1 WHERE user_email='$chEmail'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$hashPasswordCheck = password_verify($oPassword, $row['user_password']);
if ($hashPasswordCheck == false) {
echo "Nesprávne heslo";
exit();
} elseif ($hashPasswordCheck == true)
$hashedPassword = password_hash($nPassword1, PASSWORD_BCRYPT);
$sql = "UPDATE users1 SET user_password='$hashedPassword' WHERE user_email='$chEmail'";
}
}
}
}
?>
我的密码不想在我的sql数据库中更新。我不知道如何解决这个问题。有人可以编辑我的最后一部分代码到函数内容吗?