为什么我的删除位置语句不起作用

Why is my delete where statement not working?

本文关键字:语句 不起作用 位置 删除 我的 为什么      更新时间:2023-09-26

我正在尝试从表用户中删除用户。不幸的是,我一直被发送到onSqlError。我不知道为什么。当我提醒请求时,它会为我提供 getTheId 变量的正确名称。不太熟悉sql,所以也许我写错了东西。任何指示赞赏。

// DELETE RECORD
function deleteRecord(getTheId){
    deleteUser.onclick = (function () {//deleteUser is an element generated for each user when a button is clicked
        var sqlStr2 = 'DELETE FROM USERS WHERE username = '+getTheId+'';
        alert("SQL: " + sqlStr2); //This gives me the statement above with the correct name of the user clicked.
        if (db){
            console.log("db is there");//this logs
            db.transaction(function(tx) {  
                   tx.executeSql(sqlStr2);
            }, onSqlError, onSqlSuccess); //THEN I GET SENT TO ERROR
        }
    });
}

试试这个:

var sqlStr2 = "DELETE FROM USERS WHERE username = '"+getTheId+"'";

尝试在语句末尾添加";",尽管没有错误消息很难分辨。