自从昨晚成功尝试后,我的登录表单重定向到用户主页时遇到了问题。填写表格后,我会按提交,但我仍然在同一页面,除了表格将被清除。 所以我决定使用$ _POST方法回显我的输入,在重新提交表单后,我看到两个条目的页面显示 1 。我的代码出了什么问题?
<!DOCTYPE html>
<?php require_once("../Includes/Session.php"); ?>
<?php require_once("../Includes/DB_Connection.php"); ?>
<?php require_once("../Includes/Functions.php"); ?>
<?php require_once("../Includes/Validation_Functions.php"); ?>
<head>
<title> eTransport: Login</title>
<link rel="stylesheet" type="text/css" href="Login_Style.css">
</head>
<html>
<body>
<div class="div1">
<h1 class="title"> Online eTransport Service (Fiji) </h1>
<div>
<form action="Login.php" method="POST">
eTransport_ID: <input type="text" name="eTransport_ID"><br>
Password: <input type="password" name="Password"><br>
<input type="submit" name="Submit" value="submit"><br>
<?php echo isset($_POST['eTransport_ID']); ?><br>
<?php echo isset($_POST['Password']); ?>
</form>
</div>
</div>
</body>
</html>
<?php
$id = isset($_POST['eTransport_ID']);
$password = isset($_POST['Password']);
$checked_id= mysql_prep($id);
$query = "SELECT eTransport_ID ,Password FROM etrans_id_details";
$login_set = mysqli_query($conn, $query);
while ($row = mysqli_fetch_assoc($login_set)){
if ($checked_id == $row["eTransport_ID"] AND $password == $row["Password"]){
redirect_to("Home.php");
}
}
?>
我的代码输出$ _POST:
答案 0 :(得分:1)
这是一个很长的答案。
更换
$id = isset($_POST['eTransport_ID']);
$password = isset($_POST['Password']);
与
$id = $_POST['eTransport_ID'];
$password = $_POST['Password'];
并添加代码以测试它是否已设置。