Adebayo Ojo
asked on
Updating Password with Ajax
What am I doing wrongly in these code? I want to update user password without refreshing the page, but this is not working as my code stops at
HTML
Ajax
PHP - functions/changePwd.php
_("pmessage").innerHTML = 'please wait ...';
on the jquery/ajax code. The Ajax seems not to be firing as my DB is not updated with the new password. Below are my codes:HTML
<form id='pform' method='post'>
<div id='entercurrent'>Enter Current Password:</div>
<input id='current' name='current' type='password'>
<div id='enternew'>Enter New Password:</div>
<input id='newpwd' name='newpwd' type='password'>
<div id='enterconfirm'>Confirm New Password:</div>
<input id='confirmpwd' name='confirmpwd' type='password'>
<input id='passsubmit' type='submit' value='Update Password'>
</form>
<div id='pmessage'></div>
Ajax
$(document).ready(function() {
$("#passsubmit").click(function(event) {
event.preventDefault();
var cp = $("#current").val();
var np = $("#newpwd").val();
var cf = $("#confirmpwd").val();
dataString = "cp=" + cp + "&np=" + np + "&cf=" + cf;
_("passsubmit").style.display = "none";
_("pmessage").innerHTML = 'please wait ...';
$.ajax({
type: "POST",
url: "functions/changePwd.php",
data: dataString,
success: function() {}
});
});
});
PHP - functions/changePwd.php
if(isset($_POST['cp'])) {
$currentpwd = $_POST['cp'];
$newpwd = password_hash($_POST['np'], PASSWORD_DEFAULT);
$confirmnewpwd = password_hash($_POST['cf'], PASSWORD_DEFAULT);
}
$sql = "UPDATE users SET password='$newpwd' WHERE username='$log_username'";
$query = mysqli_query($db_connect, $sql);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I figured out the issue. It's actually due to include/require of script in a wrong sub-directory. It's working fine now.