그래서 내 사이트에 암호 변경 기능을 구현하려고하는데 암호 형식 을 제출하고 페이지를 새로 고치지 않고 제출하십시오. 그래서 저는 아약스를 사용하려고합니다. 다음 PHP
AJAX 암호 변경
$('#change_Pass').submit(function(e){
$.ajax({
data: $(this).serialize(), // get the form data
type: $(this).attr('POST'), // GET or POST
url: $(this).attr('Private/change_password.php'), // the file to call
success: function(response) { // on success..
$('#success_div).html(response); // update the DIV
},
error: function(e, x, r) { // on error..
$('#error_div).html(e); // update the DIV
}
});
e.preventDefault();
});
그리고 :
<form id="change_Pass" action="" method="post">
Current Password<input type="password" id="change_password" name="change_password"><br>
New Password<input type="password" id="new_password" name="new_password"><br>
Verify Password<input type="password" id="verify_password" name="verify_password"><br>
<input type="submit" value="Submit">
</form>
그리고 JQuery와 : 여기 내 HTML의
<?php
$usr = $_SESSION["username"];
$old_pwd = $_POST["change_password"];
$new_pwd = $_POST["new_password"];
$link = new PDO('mysql:host=*;dbname=*;charset=UTF-8','*','*');
$query = "SELECT *
FROM Conference
WHERE Username = :un";
$stmt = $link->prepare($query);
$stmt->bindParam(':un', $usr);
$stmt->execute();
$row = $stmt->fetchAll();
$hash = $row[0]["Password"];
$is_correct = Bcrypt::check($old_pwd, $hash);
if($is_correct) {
$query = "UPDATE Conference
SET `Password`=:new_pwd
WHERE Username = :usr";
$stmt = $link->prepare($query);
$stmt->bindParam(':new_pwd', $new_pwd);
$stmt->bindParam(':usr', $usr);
$stmt->execute();
}
그러나 나는 몇 가지에 붙어있어.
1) 데이터를 serialize하지 않고 change_password.php에 게시하여 $_POST
을 사용할 수있게하려면 어떻게해야합니까?
2) change_password가 올바르게 보이나요? 기본적으로 사람이 current password
에 입력 한 내용을 데이터베이스에있는 기존 비밀번호와 대조합니다. 일치하는 경우 암호가 변경됩니다.
또한 $ ('# success_div')를 만듭니다 .html (응답); // 정확한 DIV를 업데이트하십시오. –