php - 如何通过用户主页重定向
问题描述
我正在尝试将索引页面重定向到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>";
}
}
?>
解决方案
推荐阅读
- sql - 如何防止非结果附加到联合子句
- firebase - Firebase 实时数据库元素意外为零(Swift)
- hive - 如何在 Hive 中按周数获取一周的开始日期?一周的第一天应该是星期一
- python-3.x - 如果 pool.map 函数中的某个进程崩溃了怎么办?
- react-native - react-native 在启动应用程序时引发奇怪的 python 错误
- neo4j - 检查路径的每个关系会触发太多的 dbhits
- tomcat - 如何在 grails 网页中显示 CCTV rtsp 流
- python - 如何发出命令更改频道冷却时间 discord.py
- wpf - 为什么我的 ItemsControl 将所有项目都显示在彼此之上
- gpgpu - 是否有任何计算机病毒会影响 gpus?