首页 > 解决方案 > 如何通过用户主页重定向

问题描述

我正在尝试将索引页面重定向到user-home.php页面。但是当我尝试登录时显示错误的用户。如何通过此条件重定向到用户主页。期待帮助。提前致谢。下图是注册页面的数据库属性。

注册数据库

这是我的索引页面代码

<form  method="post" action="" autocomplete="on">
    <h3>Log in</h3>
    <hr>
    <p>
        <label for="username" class="uname" data-icon="u" > Your username </label>
        <input id="username" name="username" required="required" type="text"/>
    </p>
    <p>
        <label for="password" class="youpasswd" data-icon="p"> Your password </label>
        <input id="password" name="password" required="required" type="password"/>
    </p>
    <p class="login button">
        <input type="submit" name="login" value="Login" />
    </p>

</form>
<h2>dont have an account signup here</h2>
<li><a href="signup-form.php">signup</a></li>





</table>

<?php
if(isset($_POST['login'])){
    $username = $_POST['username'];
    $password = $_POST['password'];

    $q=$db->prepare("SELECT* FROM signup WHERE username='$username' && password='$password'" );
    $q->execute();
    $row=$q->fetch(PDO::FETCH_OBJ);
    $count = $q->rowcount();

    if ($count >= 1){    
        session_start();
        $_SESSION['id'] = $row['user_id'];
        header('location:user-home.php');
    }else{
        echo "<script>alert ('Wrong User')</script>";
    }

}
?>

标签: php

解决方案


推荐阅读