I'm trying to perform an SQL update statement through calling a PHP file via an AJAX call, however this statement is not being performed even though the AJAX call is successful. Can anyone see an issue with my code below?
AJAX request
$.ajax({
type: 'POST',
url: 'changedetails.php',
data: {'firstName':$('#firstName').val(), 'lastName':$('#lastName').val(), 'address':$('#address').val()},
success: function(data) {
location.href = 'patientaccount.php'
},
complete: function(data, textStatus) {
}
});
});
changedetails.php (relevant code)
//declare variables with sent parameters
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$address= $_POST['address'];
$sessionusername = $_SESSION["username"];
$sql = "UPDATE PATIENT SET FIRSTNAME = '$firstName', LASTNAME= '$lastName', ADDRESS =
'$address' WHERE username = '$sessionusername'";
if (mysqli_query($conn, $sql)) {
echo "success";
exit();
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
//close connection
mysqli_close($conn);