[英]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.