为什么我的删除where语句不起作用?

时间:2015-01-27 17:12:18

标签: javascript sql sqlite

我正在尝试从表USERS中删除用户。不幸的是,我一直被发送到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
        }
    });
}

2 个答案:

答案 0 :(得分:1)

试试这个:

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

答案 1 :(得分:0)

尝试添加';'在你的陈述结束时,虽然没有错误信息,但很难说。