Can somebody help regarding to my PHP and jQuery? I try to change my password using PHP, jQuery and Ajax. I know this method is kind of weird. But I want to explore more about Ajax, jQuery with PHP. I want to UPDATE my password without showing or typing the current password. I want my textbox empty and if I input something it will change my password in my db table. Don't need to type my current password. My problem is it didn't update my password. How can I update my db password? depends who is login.
<?php
$conn = new mysqli("localhost", "root", "", "mydb");
if(isset($_POST["btnChange"])) {
$checkUser = $conn->query("SELECT * FROM tbl_user WHERE id= $_SESSION[id]");
if ($checkUser->num_rows > 0) {
$conn->query("UPDATE tbl_user SET password = '$_POST[new_password]' WHERE id= $_SESSION[id]");
echo "Update Successfully!";
}
}
?>
$(document).ready(function(){
$("#btnChange").click(function(){
$.ajax({
url:"insert.php",
method:"post",
data:{btnChange: "", new_password: $("#new_password").val(),},
success: function(data){
alert(data);
}
});
});
});
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery/jquery.js"></script>
<script src="changeapasswordjs.js"></script>
<title>Change password</title>
</head>
<body>
<h1>Change password</h1>
<form id="simpleForm">
<div>
<label for="new_password">Your new_password</label>
<input type="password" name="new_password" id="new_password" />
</div>
<br>
<div>
<button id="btnChange">Change password</button>
</div>
</form>
</body>
</html>