weixin_33725270 2016-03-25 17:54 采纳率: 0%
浏览 81

无法从数据表中删除

I have a problem when i want to delete, it's always still loading and not deleting data. the data that i want to delete already shown, but when i click ok, it won't deleting just loading. is there something wrong ? because create, read and update already success.
table: users
field :

  • id
  • username
  • password
  • level



this is the sample of the code :

index.php

function deleteUser(id) {
    clearModals();
    $.ajax({
        type: "POST",
        url: "crud.php",
        dataType: 'json',
        data: { id: id, type: "get" },
        success: function (data) {
            $("#removeWarning").show();
            $("#myModalLabel").html("Delete User");
            $("#id").val(data.id);
            $("#type").val("delete");
            $("#username").val(data.username).attr("disabled", "true");
            $("#password").val(data.password).attr("disabled", "true");
            $("#level").val(data.level).attr("disabled", "true");
            $("#myModals").modal("show");
            waitingDialog.hide();
        }
    });
}

crud.php

case "delete":
     $SQL = mysqli_query($con, "DELETE FROM users WHERE username='".$_POST['username']."'");
        if($SQL){
            echo json_encode("OK");
        }           
        break;
}

server.php

while ( $aRow = $rResult->fetch_assoc() ) {
    $row = array();
    $btn = '<a href="#" onClick="showModals(\''.$aRow['id'].'\')">Edit</a> | 
    <a href="#" onClick="deleteUser('.$aRow['id'].')">Delete</a>';
    for ( $i=0 ; $i<$iColumnCount ; $i++ ) {
        $row[] = $aRow[ $aColumns[$i] ];
    }
    $row = array( $btn, $aRow['username'], $aRow['password'], $aRow['level'] );
    $output['aaData'][] = $row;
}
  • 写回答

1条回答 默认 最新

  • weixin_33744854 2016-03-25 18:02
    关注

    You are sending id with ajax and in crud.php you are deleting $_post['username'], and you didn't event send that

    change your sql query to:

    mysqli_query($con, "DELETE FROM users WHERE username='".$_POST['id']."'");
    

    and maybe switch username= with id ? or edit what are you sending

    评论

报告相同问题?