Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery移动登录表单的php实现_Php_Mysqli - Fatal编程技术网

jquery移动登录表单的php实现

jquery移动登录表单的php实现,php,mysqli,Php,Mysqli,我一直在与代码斗争!!我不断得到无效的密码错误,无论多少次我调整哈希在哪里或在哪里检查密码,我仍然得到它,即使我为不同的用户放置了正确的密码…我真的需要一些帮助! my db中的“用户”表为 身份证件 用户名 密码sha1 全名 流动电话号码 用户类型 这是我目前正在努力工作的代码 <body> <div data-role="page" id="login"> <div data-role="header" data-th

我一直在与代码斗争!!我不断得到无效的密码错误,无论多少次我调整哈希在哪里或在哪里检查密码,我仍然得到它,即使我为不同的用户放置了正确的密码…我真的需要一些帮助! my db中的“用户”表为 身份证件 用户名 密码sha1 全名 流动电话号码 用户类型 这是我目前正在努力工作的代码

       <body>
      <div data-role="page" id="login">
        <div data-role="header" data-theme="c">
          <h2 align="center"><strong>Sign In</strong></h2>
        </div>
       <div data-role="content">
          <form name="login" class="ui-corner-all" method="post" action="">
            <label for="username" class="ui-hidden-accessible">Username:</label>
            <input type="text" id="username" name ="username" placeholder="Username" required>
            <br>
            <br>
            <label for="password" class="ui-hidden-accessible">Password:</label>
            <input type="password" id="password" name ="password" placeholder="Password"  required>
            <br>
            <fieldset class="ui-grid-a">
            <div class="ui-block-a">
          <input name="login" type="submit"  id="login" formmethod="POST"          value ="login" data-ajax="false" data-theme="b">
          </div>
          <div class="ui-block-b">
          <a href="Registration.html" data-ajax="false" data-role="button"     data-theme="b">Not a user? Sign Up</a></div>
      </fieldset> 
          </form>
          <?php   
      if (isset($_POST["login"]) && !empty($_POST["login"])) {

      $user = stripslashes($_POST['username']);
      $pass = stripslashes($_POST['password']);
      $user = mysqli_real_escape_string($link, $_POST['username']);
      $pass = mysqli_real_escape_string($link, hash("SHA1",($_POST['password'])));

      if ($user && $pass) {  // CHECK ALL FIELD HAS BEEN FILLED UP

      // QUERY FROM DATABASE
      $sql = "SELECT * FROM users WHERE username='".$user."'";
      $query =mysqli_query($link,$sql) or die(mysqli_error($link));

      $numrows = mysqli_num_rows($query);

      if($numrows !== 0)
      {
      while ($row = mysqli_fetch_assoc($query))
      {
          $username = $row['username'];
          $password = $row['password'];

          }

          if($user==$username && $pass==$password)
          {
              echo "you are logged in";
              @$_SESSION['username'] = $username;
              }

              else {
                  echo "your password is incorrect";    
                  }
      }
                  else
                      die ("that user doesn't exist!");
                  }
                  else
                      die ("Please enter a username and password");
      }


          ?>

你的代码运行良好。我知道你已经登录了。 我刚刚添加了session\u start并替换了mysqli\u real\u escape\u字符串中的变量

    <body>
    <div data-role="page" id="login">
        <div data-role="header" data-theme="c">
            <h2 align="center">
                <strong>Sign In</strong>
            </h2>
        </div>
        <div data-role="content">
            <form name="login" class="ui-corner-all" method="post" action="">
                <label for="username" class="ui-hidden-accessible">Username:</label>
                <input type="text" id="username" name="username"
                    placeholder="Username" required> <br> <br> <label for="password"
                    class="ui-hidden-accessible">Password:</label> <input
                    type="password" id="password" name="password"
                    placeholder="Password" required> <br>
                <fieldset class="ui-grid-a">
                    <div class="ui-block-a">
                        <input name="login" type="submit" id="login" formmethod="POST"
                            value="login" data-ajax="false" data-theme="b">
                    </div>
                    <div class="ui-block-b">
                        <a href="Registration.html" data-ajax="false" data-role="button"
                            data-theme="b">Not a user? Sign Up</a>
                    </div>
                </fieldset>
            </form>
            <?php   
            $link = new mysqli("localhost", "root", "root", "test");
            /* check connection */
            if (mysqli_connect_errno()) {
                printf("Connect failed: %s\n", mysqli_connect_error());
                exit();
            }

            if (isset($_POST["login"]) && !empty($_POST["login"])) 
            {
                $user = stripslashes($_POST['username']);
                $pass = stripslashes($_POST['password']);
                $user = mysqli_real_escape_string($link, $user);
                $pass = mysqli_real_escape_string($link, hash("SHA1",($pass)));

                if ($user && $pass) {  // CHECK ALL FIELD HAS BEEN FILLED UP


                    // QUERY FROM DATABASE
                    $sql = "SELECT * FROM users WHERE username='".$user."'";
                    $query =mysqli_query($link,$sql) or die(mysqli_error($link));

                    $numrows = mysqli_num_rows($query);

                    if($numrows !== 0)
                    {
                        while ($row = mysqli_fetch_assoc($query))
                        {
                            $username = $row['username'];
                            $password = $row['password'];
                        }

                        if($user==$username && $pass==$password)
                        {
                            session_start();
                            echo "you are logged in";
                            @$_SESSION['username'] = $username;
                        }
                        else 
                        {
                            echo "your password is incorrect";
                        }
                    }
                    else
                        die ("that user doesn't exist!");
                }
                else
                    die ("Please enter a username and password");
            }
            ?>
        </div>
    </div>
</body>

你的问题是什么?错误是什么?如果打印$pass值怎么办?它是否与数据库值相同?试着一步一步地调试它。嘿,小家伙……我的问题是我在代码上犯了什么错误?我一直得到的密码是不正确的…什么是我应该把仙人掌的代码行?在哪里…密码的回音不正确?我已经排除了错误…但是我仍然通过您的调整得到了不正确的密码,但是代码更好!请回显$sql并在数据库编辑器或命令提示符下运行它。让我知道运行该命令时得到的结果。这就是我将其作为回声错误SELECT*从username='eliza'Ok让我们忘记数据库时得到的结果。您能否在$numrows=mysqli\u num\u rows$query行之后回显$numrows;如果$user=$username&&$pass==$password,则在第行前面回显$username和$password。请将结果粘贴给我。num行的回音为1您的密码对用户不正确,并传递给jonny和8103504b08e1015