提交表单时密码字段不起作用

时间:2018-04-08 19:25:55

标签: javascript php jquery ajax mysqli

其实我想建立一个用户填写的注册系统     注册表单与他们的电子邮件和用户名唯一的强大     密码

我的register.php代码......

<?php include 'inc/header.php'; ?>


          <?php 
           Session::checklogin();
          ?>



     <div class="loginBoxx">
         <div class="jumbotron">
        <h2>Sign Up Here</h2>
        <form action="" method="post">
          <div class="form-group">
            <label>Your Name</label>
            <input type="text" name="name" class="form-control" id="name" placeholder="Enter your name" />
            </div>
            <div class="form-group">
            <p>Your Email</p>
            <input type="text" name="email" class="form-control" id="email" placeholder="Example@gmail.com" />
            </div>
            <div class="form-group">
            <p>Your User Name</p>
            <input type="text" name="username" class="form-control" id="username" placeholder="Enter your username" />
            </div>
            <div class="form-group">
            <p>Enter Password</p>
            <input type="password" name="password" class="form-control" id="password"/>
            </div>
            <div class="form-group">
            <p>Retype Password</p>
            <input type="password" name="confirm" class="form-control" id="confirm"/>
             </div>
            <button type="submit" id="regsubmit" class="btn btn-success"> Register </button>
             <span id="state"></span>
            <h4>Already Registered? <a href="index.php">Login</a></h4>


        </form>
        </div>
    </div>



       <?php include 'inc/footer.php'; ?>     

我的主要js代码...

  function(){   //For user Registration  
   $("#regsubmit").click(function(){
        var name     = $("#name").val();
        var email    = $("#email").val();
        var username = $("#username").val();
        var password = $("#password").val();


        var datastring = 'name='+name+'&email='+email+ '&password='+password+ '&username='+username;
        $.ajax({
          type: "POST",
          url:"getregister.php",
          data: datastring,
           cache: false,
          success: function(data){
            $("#state").html(data);
          }
        });
        return false;   }); 

我的getregister.php代码..

<?php   $filepath = realpath(dirname(__FILE__));    include_once
($filepath.'/classes/User.php');    $usr = new User();

   if($_SERVER['REQUEST_METHOD'] == 'POST'){
        $name       = $_POST['name'];
        $email      = $_POST['email'];
        $username   = $_POST['username'];
        $password   = $_POST['password'];



        $userregi = $usr->userRegistration($name, $email, $username, $password);    }

    ?>

我的验证课,我使用user.php ...

<?php    $filepath =
realpath(dirname(__FILE__));    include_once
($filepath.'/../lib/Database.php');    include_once
($filepath.'/../lib/Session.php');    include_once
($filepath.'/../helpers/Format.php');

     class User {       private $db;    private $fm;
        function __construct(){
        $this->db = new Database();
        $this->fm = new Format();
           }
    public function userRegistration($name, $email, $username, $password){
      $name     = $this->fm->validation($name);
      $email    = $this->fm->validation($email);
      $username = $this->fm->validation($username);
      $password = $this->fm->validation($password);




      $name     = mysqli_real_escape_string($this->db->link, $name);
      $email    = mysqli_real_escape_string($this->db->link, $email);
      $username = mysqli_real_escape_string($this->db->link, $username);
      $password = mysqli_real_escape_string($this->db->link, md5($password));

     // $pass   = password_hash( $password, PASSWORD_BCRYPT, array('cost' => 11));

       if($name == ""){
         echo "<span class=error>Field must not be empty!</span>";
         exit();
       }
       if($email == ""){
         echo "<span class=error>Field must not be empty!</span>";
         exit();
       }
       if($username == ""){
         echo "<span class=error>Field must not be empty!</span>";
        exit();
       } 

       if($password == ""){
         echo "<span class=error>Field must not be empty!</span>";
         exit();
       }

       $check_query = "SELECT * FROM tbl_user where email = '$email' OR username= '$username'";
       $run_query = $this->db->select($check_query);
       if($run_query != false){
        echo "<span class=error>Email or username already exist!</span>";
       } else{
         $query = "INSERT INTO tbl_user(name, email, username, password) VALUES('$name', '$email', '$username', '$password')";
          $insert_row = $this->db->insert($query);
          if($insert_row){
            echo "<span class='success'>Registration Successfully Done !</span>";
            exit();
          }else{
            echo "<span class='error'>ERROR....Not Registered !</span>";
            exit();
          }
        }

       } }

您能否告诉我如何使用指定密码提交此表单?这里我使用MySQL数据库,我的db_exam名称是db_exam。

0 个答案:

没有答案