我正在制作这个简单的代码来验证用户。带有表单的页面是:>login.php。使用以下代码。
登录.php:
<html>
<body>
<div style="position:absolute;left:300px;top:300px;width:300px;height:100px;z-index:9;>
<form name="form1" method="POST" action="check.php">
Username:<br />
<input type="text" name="Username" />
<br /><br />
Password:<br />
<input type="password" name="Password" />
<br /><br /><br/>
<input type=button onClick="location.href='check.php'" value='Continue' name='continue'/>
</form>
</div>
</body>
</html>
表单字段值在下一个 php 页面中使用,代码如下:
检查.php:
<?php
session_start();
$con = mysql_connect("localhost", "root", "");
mysql_select_db("aviation", $con) or die(mysql_error());
if (isset($_POST['continue'])) {
$userName = $_POST[Username];
$passWord = $_POST[Password];
mysql_select_db('aviation');
$query = "select * from users where Username='" . $userName . "'and Password='" . $passWord . "'";
$result = mysql_query($query, $con);
if (!$result) {
die('Could not enter data: ' . mysql_error());
}
$rows = mysql_num_rows($result);
if ($rows == 1) {
$_SESSION['Username'];
$_SESSION['Password'];
echo "Successful";
echo "<BR>";
echo "You are authorized to update the status of Bays.";
echo "<BR>";
$Msg = "Redirecting....";
echo '<script type="text/javascript">
alert("' . $Msg . '");
</script>';
header("location:upbstatus.php");
} elseif ($userName == "" || $passWord == "") {
$errorMsg = "Data was not entered <br/> Enter Username and Password";
echo '<script type="text/javascript">
alert("' . $errorMsg . '");
</script>';
else {
$errorMsg = "Data Does Not Match <br/> Re-Enter Username and Password";
$errorMsg = "Data was not entered <br/> Enter Username and Password";
echo '<script type="text/javascript">
alert("' . $errorMsg . '");
</script>';
}
} else {
echo (" =============== not SET ===============");
}
?>
它总是返回: =============== not SET ===============
我很困惑为什么会这样。有人可以帮忙吗?将不胜感激。
谢谢你。