簡體   English   中英

AJAX 不更新 MySql 數據

[英]AJAX not updating MySql data

我創建了這個 PHP 腳本來更新用戶的狀態。 運行以下代碼時遇到一些困難。 該頁面的代碼如下:-

    $query = "DELETE FROM users WHERE id='$id' ";
    $query_run = mysqli_query($conn, $query);

    if($query_run)
    {
        $_SESSION['status'] = "Successfully Deleted";
        header('Location: index.php');
    }
    else
    {
        $_SESSION['status'] = "Something Went Wrong.!";
        header('Location: index.php');
    }

此處的查詢無法運行。 以下 ajax 代碼使用 POST 請求將數據發送到此頁面

$.ajax({
            type: "POST",
            url: "code.php",
            data: {
                    'checking_edit_btn': true,
                    'student_id': stud_id,
                      },
            success: function (response) {
            $.each(response, function (key, value) { 
            $('#edit_id').val(value['id']);
            });
            $('#editStudentModal').modal('show');
            };
            });

更新它現在正在工作,這是最終代碼:

$.ajax({
        type: "POST",
        url: "code.php",
        data: {
               'delete_student': true,
                'student_id': stud_id,
                  },
        success: function (response) {
        $.each(response, function (key, value) { 
        $('#edit_id').val(value['id']);
        });
        $('#editStudentModal').modal('show');
        };
        });

你在哪里發送'update_student'/'delete_student'?

嘗試添加到數據

update_student: true

要么

delete_student: true

取決於按鈕

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM