繁体   English   中英

JavaScript登录功能无法使用WebSQL

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM