简体   繁体   English

登录表单HTML5和jquery

[英]Login Form HTML5 and jquery

I have created table in the database called student and a register form which is working to store database when student register.My problem is in the login form.How do i check whether the matric and password in the form matched with matric and password in the database.Thanks 我在数据库中创建了一个名为Student的表,并创建了一个注册表单,该表单可以在学生注册时存储数据库。我的问题是在登录表单中。如何检查表单中的矩阵和密码是否与表单中的矩阵和密码匹配数据库。谢谢

 function createDB(tx){
              //  tx.executeSql('DROP TABLE IF EXIST hfu');
                tx.executeSql('CREATE TABLE IF NOT EXISTS STUDENT (matric, name, password)');
        }

  }
  function insertDB(tx){
      var _matric=$("[name='matric']").val();
      var _name=$("[name='name']").val();
      var _password=$("[name='password']").val();
      var sql ='INSERT INTO STUDENT (matric, name, password) VALUES (?,?,?)';
      tx.executeSql(sql,[_matric,_name,_password],sucessQueryDB,errorCB);
  }

   function submitForm(){
      db.transaction(insertDB, errorCB);
      $.mobile.changePage("#page2",{reverse:false,transition:"slide"});
      return false;
   }

   function loginForm(){

   }

        </script>

<div data-role="page" id="page4" data-add-back-btn="true">
    <div data-role="header">
        <h1>Login</h1>
    </div>
    <div data-role="content">
        <form method="POST" onsubmit="return loginForm()" id="myForm2" data-ajax="false">

        <input name="matric" type="text" placeholder="Matric">
        <input name="password" type="password" placeholder="Placeholder">
        <input type="submit" value="Submit">

        </form>
    </div>

</div>

Instead of doing the insert, you need to do a select transaction to see if the value exists. 除了执行插入操作,您还需要执行选择事务以查看该值是否存在。 The select result will be a resultset you can check the size of. 选择结果将是一个结果集,您可以检查其大小。 If it is 0, do an insert, if it is 1, handle it however it makes sense to you (show an error to user or whatever). 如果为0,则执行插入操作;如果为1,则进行插入操作,但对您有意义(向用户显示错误或其他错误)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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