PHP登录,登录按钮刷新页面

时间:2018-03-18 21:02:03

标签: php html mysql sql html5

您好我正在尝试在我的网站上实施PHP登录系统,我正在遵循本指南:' https://www.tutorialspoint.com/php/php_mysql_login.htm'

我已完全按照本指南进行操作,但似乎无法正常工作。

每当我点击登录按钮时,似乎只是刷新当前页面,尽管我已经告诉它转到我的index2.php页面。

我想知道是否有人能引导我解决这个问题。谢谢你提前。

这是我的login.php顶部的PHP:

<?php
   include("config.php");
   session_start();

   if($_SERVER["REQUEST_METHOD"] == "POST") {
      // username and password sent from form 

      $myusername = mysqli_real_escape_string($conn,$_POST['username']);
      $mypassword = mysqli_real_escape_string($conn,$_POST['password']); 

      $sql = "SELECT customer_id FROM customer WHERE email_adress = '$myusername' and password = '$mypassword'";
      $result = mysqli_query($conn,$sql);
      $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
      $active = $row['active'];

      $count = mysqli_num_rows($result);

      // If result matched $myusername and $mypassword, table row must be 1 row

      if($count == 1) {

         $_SESSION['login_user'] = $myusername;

         header("location: index2.php");
      }else {
         $error = "Your Login Name or Password is invalid";
      }
   }
?>

这是login.php中的html表单:

<h2 class="section-heading">Login Form</h2>
                                <form class="form-horizontal" role="form" action = "" method = "POST">
                                    <div class="form-group">
                                        <label for="username" class="control-label sr-only">Email</label>
                                        <div class="col-sm-12">
                                            <div class="input-group">
                                                <input type="email" class="form-control" id="username" name = "username" placeholder="Email">
                                                <span class="input-group-addon"><i class="fa fa-envelope"></i></span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="password" class="control-label sr-only">Password</label>
                                        <div class="col-sm-12">
                                            <div class="input-group">
                                                <input type="password" class="form-control" id="password" name="password" placeholder="Password">
                                                <span class="input-group-addon"><i class="fa fa-lock"></i></span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-12">
                                            <label class="fancy-checkbox">
                                                <input type="checkbox">
                                                <span>Remember me</span>
                                            </label>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-12">
                                            <button type="submit" class="btn btn-primary"><i class="fa fa-sign-in"></i> Sign in</button>
                                        </div>
                                    </div>
                                </form>
                                <br>
                                <p><em>Don't have an account yet?</em> <a href="#"><strong>Sign Up</strong></a>
                                    <br>
                                    <em>Forgot your password?</em> <a href="#">Recover Password</a></p>

这是session.php:

<?php
   include('config.php');
   session_start();

   $user_check = $_SESSION['login_user'];

   $ses_sql = mysqli_query($conn,"select email_adress from customer where email_adress = '$user_check' ");

   $row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);

   $login_session = $row['email_adress'];


   if(!isset($_SESSION['login_user'])){
      header("location:login.php");
   }

&GT;

1 个答案:

答案 0 :(得分:1)

<form class="form-horizontal" role="form" action = "[THIS MUST BE SET]" method = "POST">

您的表单操作=&#34;&#34;没有设定。

相关问题