[每当我单击登录按钮时,两个字段都将被删除,并且保留在与登录页面相同的页面上。我是php的新手,并尝试了其他一些东西并观看了不同的视频,但我似乎无法解决该问题,我们将不胜感激。
用户登录后,我希望他们被重定向到他们的个人资料页面,我已经将此放置在位置标题中,但是我什至无法做到这一点。
登录php页面
<?php
session_start();
require"connect.php";
include"navbar.html";
?>
<?php
if (isset($_POST['submit'])){
// Assigning POST values to variables.
$username = $_POST['StudentID'];
$password = $_POST['StudentPassword'];
// CHECK FOR THE RECORD FROM TABLE
$query = "SELECT * FROM `student_login` WHERE Student_ID='$username' and Password='$password'";
$result = mysqli_query($connection, $query);
$count = mysqli_num_rows($result);
if ($count == 1){
header('location: profile.php');
}else{
echo "Incorrect username or password";
}
}
?>
<head>
<style>
.container{
width: 400px;
height: 240px;
max-width: 400px;
min-width: 100px;
overflow: hidden;
border: 2px solid black;
border-radius: 5px;
padding: 30px;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="container">
<center>
<h3>Student Login</h3>
<form id="login-form" method="post" action="Student_Login.php" >
<table border="0.5" >
<tr>
<td><label for="StudentID">Student ID</label></td>
<td><input type="text" name="StudentID" id="StudentID"></td>
</tr>
<tr>
<td><label for="StudentPassword">Password</label></td>
<td><input type="password" name="StudentPassword" id="StudentPassword"></input></td>
</tr>
<tr>
<td><input type="submit" value="Login" />
</tr>
</table>
</form>
</center>
</div>
</body>
连接页面
<?php
$connection = mysqli_connect('localhost', 'root', '');
if (!$connection){
die("Database Connection Failed" . mysqli_error($connection));
}
$select_db = mysqli_select_db($connection, 'recordkeepingsystem');
if (!$select_db){
die("Database Selection Failed" . mysqli_error($connection));
}
?>
尝试一下:
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// your logic
}
?>
并将您的表单操作action="Student_Login.php"
更改为action=""