[英]JavaScript login function not working using WebSQL
我正在嘗試使用WebSQL和JavaScript執行登錄功能。 我寫了一個函數帶一個參數( email
)。 該函數應該在數據庫中搜索現有的電子郵件,然后它應該返回一個警告,說明電子郵件是否存在。
我還想使用該函數來搜索是否有相關密碼退出電子郵件,如果是,它應該記錄用戶,如果不是,它應該返回一條消息。 所有的幫助將非常感謝。 提前致謝。
function email_exists(email) {
mydb.transaction(function(transaction) {
transaction.executeSql("select id from user where email= " + email + " ", [], function(tx, result) {
alert("email exists");
},
function(error) {
alert("Email does not exist");
});
});
}
你可以這樣做,
function email_exists(email) {
db.transaction(function (tx) {
tx.executeSql(
'SELECT * FROM user WHERE email=? LIMIT 1',
[email],
function (tx, result) {
if(result.rows.length){
// user found
alert("User found - ", result.rows[0]);
}
else {
// email does not exists
alert("User not found");
}
},
null
);
});
}
這里要注意的一件重要事情是,您可以使用替換方法( ?
)避免sql注入,而不是在SQL查詢中連接查詢參數。
從這里進一步閱讀
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.