php重定向页面问题

aiqt4smr  于 2021-06-21  发布在  Mysql
关注(0)|答案(3)|浏览(442)

我使用php脚本登录我的应用程序。但效果不好。我想纠正这个错误。它加载同一页。我想显示如果用户名和电子邮件是好的,然后显示索引页

<?php

if(isset($_POST['submit'])){

    $email = $_POST['email'];
    $pass = $_POST['password'];

    $db = new Database();
    $db->query('select email, password from user where email = :email and password = :password');
    $db->bind(':email', $email);
    $db->bind(':password', $pass);
    $db->resultset();
    print_r($db->resultset());

    if($db->rowCount() == 1){

        header('location: index.php');  
    }

}   
?>

这是我在同一个文件中的登录表

<form method="post" action="" class="form-horizontal">

              <div class="form-group">
                  <h2 style="font-size: 25px; text-align: center; font-weight: 600; margin-bottom: 30px;">LOGIN HERE</h2>
              </div>
              <div class="form-group">                  
              </div>
              <div class="form-group">
                  <label for="email">Email: </label>
                  <input type="email" class="form-control" id="email" name="email" required="require" placeholder="Enter email">   
              </div>
              <div class="form-group">
                  <label for="password">Password</label>
                  <input type="password" class="form-control" id="password" name="password" required="require" placeholder="Enter password">  
              </div>           

              <input type="submit" class="btn btn-primary" name="submit" value="Login"/>
      </form>
gmol1639

gmol16391#

首先,只有当您的登录详细信息正确并且与数据库中的一行匹配时,该代码才会运行
第二,请更新此代码 'select email, password from user where email = :email and password = :password'"SELECT email, password FROM user WHERE email = '$email' and password = '$password'" 最后, header('Location: index.php'); 我希望这能奏效。。。
干得好。。。

<?php  
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Connection Query
    $db = new Database();
    // Fetch Login Data
    $email = $_POST['email'];
    $pass = $_POST['password'];
    // Login Query
    $login = "SELECT email, password FROM user WHERE email='$email' and password='$pass'";
    // Query SQL
    $req = mysqli_query($db, $login);
    // Check if Row matched is Above Zero
    if (mysqli_num_rows($req) > 0) {
        // Redirect User
        header("Location: index.php");
    }
}
?>
kse8i1jr

kse8i1jr2#

更换管路

<form method="post" action="" class="form-horizontal">

具有

<form method="post" action="#" class="form-horizontal">

或者

<form method="post" action="yourfilename.php" class="form-horizontal">

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" class="form-horizontal">
qni6mghb

qni6mghb3#

假设下面的php文件名为my\u file.php

if(isset($_POST['submit'])){

    $email = $_POST['email'];
    $pass = $_POST['password'];

    $db = new Database();
    $db->query('SELECT email, password FROM user WHERE email='$email' AND  password ='$pass');
    $db->bind(':email', $email);
    $db->bind(':password', $pass);
    $db->resultset();
    print_r($db->resultset());

    if($db->rowCount() == 1){

        header('location: index.php');  
    }

}   
?>

实际上,当您按submit时并没有调用它,所以在实际操作中,您必须指定以这种形式运行哪个php文件

<form method="post" action="my_file.php" class="form-horizontal">

          <div class="form-group">
              <h2 style="font-size: 25px; text-align: center; font-weight: 600; margin-bottom: 30px;">LOGIN HERE</h2>
          </div>
          <div class="form-group">                  
          </div>
          <div class="form-group">
              <label for="email">Email: </label>
              <input type="email" class="form-control" id="email" name="email" required="require" placeholder="Enter email">   
          </div>
          <div class="form-group">
              <label for="password">Password</label>
              <input type="password" class="form-control" id="password" name="password" required="require" placeholder="Enter password">  
          </div>           

          <input type="submit" class="btn btn-primary" name="submit" value="Login"/>
  </form>

相关问题