php求助,卡在这一步了!!!
php吧
全部回复
仅看楼主
level 3
仟涟 楼主
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>用户登录</title>
</head>
<body>
<h2>用户登录</h2>
<form action="login.php" method="post">
<label for="uid">用户名:</label>
<input type="text" id="uid" name="uid" required><br><br>
<label for="password">密码:</label>
<input type="password" id="password" name="password" required><br><br>
<input type="submit" value="登录">
</form>
</body>
</html>
<body>
<?php
// 数据库连接信息
$servername = 'localhost';
$username = 'root';
$password = '123456';
$dbname = 'schooldb';
// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);
// 检查连接
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
// 获取用户输入
$uid = $_POST['uid'];
$password = $_POST['password'];
// 防止SQL注入
$uid = $conn->real_escape_string($uid);
$password = $conn->real_escape_string($password);
// 查询数据库
$sql = "SELECT * FROM Userinfo WHERE U_name = '$uid' AND U_password = '$password'";
$result = $conn->query($sql);
// 判断登录
if ($result->num_rows > 0) {
$user = $result->fetch_assoc();
$userType = $user['U_type'];
// 根据用户类型跳转到不同界面
switch ($userType) {
case 'A': // 管理员
header('Location: admin_page.php');
break;
case 'T': // 教师
header('Location: teacher_page.php');
break;
case 'S': // 学生
header('Location: student_page.php');
break;
default:
echo "未知的用户类型";
}
} else {
echo "用户名或密码错误!";
}
// 关闭连接
$conn->close();
?>
为什么已经创建了teacher_page.php,student_page.php,admin_page.php,数据库也连接了,但是输入用户名密码后老是跳转404找不到呢
2024年06月09日 15点06分 1
level 3
仟涟 楼主
2024年06月09日 15点06分 2
level 3
仟涟 楼主
究竟是为什么,我被困在这个问题好久了
2024年06月09日 15点06分 3
level 3
仟涟 楼主
2024年06月09日 15点06分 4
level 16
你有一个文件叫login.php么,或者把404时候地址栏里显示的地址截出来啊
2024年06月09日 15点06分 5
已经解决了!谢谢
2024年06月10日 08点06分
level 6
1. 404页面的地址栏也截图出来
2. 网址是localhost(不含www的)
2024年06月10日 07点06分 6
已经解决了!谢谢
2024年06月10日 08点06分
level 15
[啊]
2024年06月25日 00点06分 7
1