简体   繁体   English

我如何使用此代码重定向到用户主页

[英]how i can redirect to user-home page with this code

i am trying to redirect my login page to user-home page. 我试图将我的登录页面重定向到用户主页。 my code is not showing any error but login page is not redirecting to user-home page. 我的代码未显示任何错误,但登录页面未重定向到用户主页。 badly expecting a proper solution. 迫切期望一个适当的解决方案。 Thanks in advance. 提前致谢。 the following image is the databse details of signup page. 下图是注册页面的数据库详细信息。

enter image description here 在此处输入图片说明

here is my code of index page 这是我的索引页代码

enter code here 在这里输入代码

<tr> 
<td width="200px" height="70px" style="color: gray;"><b>ENTER USERNAME</b></td>
                            <td width="100px" height="70px" style="border-bottom: 1px solid black;color: gray;" ><input type="text" name="username" placeholder="ENTER USERNAME" style="width: 150px;height: 35px;background:none; border: none;"></td>
                        </tr>
                        <tr>
                            <td width="200px" height="70px" style="color: gray;"><b>ENTER PASSWORD</b></td>
                            <td width="200px" height="70px" style="border-bottom: 1px solid black;color: gray;" ><input type="PASSWORD" name="password" placeholder="ENTER PASSWORD"style="width: 150px;height: 35px;background: none; border: none;"></td>

                        </tr>
                        <tr>
                            <td><input type="submit" name="login" value="login"style="width: 150px;height: 35px;  background:none;border-radius: 10px; border-color: gray; padding: 10px  "></td>
                        </tr>
                    </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'];

    $query = $db->query("select * from signup where username = '$username' && password = '$password'");
    $count = $query->rowcount();
    $row = $query->fetch();
    if ($count > 1){
    session_start();
    $_SESSION['id'] = $row['user_id'];
     header('location:user-home.php'); 
    }else{
     header('location:index.php'); 
    }
    }
    ?>

The problem is with the following condition 问题在于以下情况

if($count > 1){
}

If there's an entry with the associated username and password in the database then $query->rowcount(); 如果数据库中存在带有相关用户名和密码的条目,则$query->rowcount(); will return the no of rows selected which should be one(1). 将返回选择的行数(应为one(1))。 The condition should be 条件应该是

if($count == 1){
  //home-page
}
else{
 //index page
}

Please change if ($count > 1){} to if ($count > 0){} 请将if ($count > 1){}更改为if ($count > 0){}

Your code looks like : 您的代码如下:

if ($count > 0){
    session_start();
    $_SESSION['id'] = $row['user_id'];
     header('location:user-home.php'); 
    }else{
     header('location:index.php'); 
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将用户重定向到laravel 4中的路由中的主页 - How to redirect the user to home page in routes in laravel 4 如何通过另一个显示成功消息的页面(成功页面)重定向到页面(主页)? - How can i redirect to a page (home) via another page(success page) where some success message is to be displayed? 如何在symfony中将404重定向到home? - How can I redirect 404 to home in symfony? 用户注销后单击“后退”按钮时,如何重定向到首页? - How can I redirect to home when user click on back button after logout? Codeigniter:当用户注销后单击“后退”按钮时,如何重定向到首页? - Codeigniter: How can I redirect to home when user click on back button after logout? 什么是CakePHP 3主页? 我不能重定向到那个 - What is CakePHP 3 home page? I can't redirect to that 单击浏览器的后退按钮时如何在主页上重定向 - how can i redirect on the home page when i click on browser's back button 成功登录后如何使用jQuery将用户重定向到主页 - How to redirect the user to the home page with jQuery after successful login 我如何将我的用户和管理员重定向到其他页面 - How can i redirect my user and admin to different page 如果用户已经登录,则需要在主页上重定向 - Need To redirect At home page If user Already logged in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM