为什么我的 delete where 语句不起作用?
Why is my delete where statement not working?
我正在尝试从 table 个 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
}
});
}
尝试添加“;”到你语句的末尾,虽然没有错误消息,但很难判断。
试试这个:
var sqlStr2 = "DELETE FROM USERS WHERE username = '"+getTheId+"'";
我正在尝试从 table 个 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
}
});
}
尝试添加“;”到你语句的末尾,虽然没有错误消息,但很难判断。
试试这个:
var sqlStr2 = "DELETE FROM USERS WHERE username = '"+getTheId+"'";