未在PHP中执行SQL UPDATE语句

时间:2019-04-03 01:45:33

标签: php sql sql-update

我正在尝试通过AJAX调用来调用PHP文件来执行SQL更新语句,但是即使AJAX调用成功,也不会执行该语句。谁能在下面看到我的代码有问题?

AJAX请求

 $.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(相关代码)

//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);

0 个答案:

没有答案