I want to make a password check where the javascript variable is the password that the user has written. I want to check if it is correct and I did that by comparing what the user wrote to my php variable which stores the actual value.
This is not a secure solution. How can I change it. I want the if statement to be at the same place as before?
Her is my code:
var password=$("#password").val();
if(password!='<?php echo "$password"; ?>'){
alert("No changes has been made due to wrong password.");
}
else{
$.ajax({
type: "POST",
url: "modify_profile.php",
data: {"firstname":firstname,"lastname":lastname},
success: function( data){
}
});
}
});
Here is modify_profile.php.
<?php
require("../db/connect.php");
$email='test@gmail.com';
$written_password=( $_POST['firstname']);
if( isset($_POST['firstname']))
{
$firstname=( $_POST['firstname']);
$query=mysqli_query($dbcon, "UPDATE user SET first_name='$firstname' WHERE email='$email'");
$result = mysqli_query($dbcon,$query);
}
if( isset($_POST['lastname'])) {
$lastname=( $_POST['lastname']);
$query=mysqli_query($dbcon, "UPDATE user SET last_name='$lastname' WHERE email='$email'");
$result = mysqli_query($dbcon,$query);
}
require("../db/close.php")
?>