这是有登录表单的主页的代码:
<?php
session_start();
if(isset($_SESSION['fb'])){
echo $_SESSION['fb'];
session_destroy();
}
?>
<html>
<head><title></title>
</head>
<body bgcolor=#818181>
<center><img src=logo.png>
<br>
<img src=voterslogin.png><br>
<a href=voterregister.php><font style='font-family:Century Gothic' size=2>Register</a><br>
<form action="login.php" method="post">
<input type="text" name="login" size=11 style="background-image:url(field.png); border: 2px; "><br>
<input type="password" name="password" size=11 style="background-image:url(field.png); border: 2px; "><br>
<input type="image" src="submit.png" alt="Submit button" name="submit"><br>
</form>
____________________________________________________
<br>
<img src=text1.png><br>
<a href=mayor.html><img src=menu1.gif></a><img src=bullet.png><a href=vicemayor.html><img src=menu22.gif></a><img src=bullet.png><a href=senator.html><img src=menu3.gif></a>
<img src=bullet.png><a href=congressman.html><img src=menu4.gif></a><br><a href=councilor.html><img src=menu5.png></a><img src=bullet2.png><a href=partylist.html><img src=menu6.gif></a>
<br>
____________________________________________________
<br><br><br>
<a href=adminlogin.php><img src=login.png></a><br>
</body>
</html>
这是登录检查文件:
<?php
session_start();
if(isset($_POST['submit'])){
$username = $_POST['login'];
$password = $_POST['password'];
if(!empty($username) && !empty($password)){
mysql_connect('localhost', 'root', '');
mysql_select_db('voters');
$result = mysql_query("SELECT * FROM tbvoter WHERE username='$username' AND password='$password'");
if(mysql_num_rows($result) == 1){
$row = mysql_fetch_array($result);
$_SESSION['voter_id'] = $row[0];
header('Location: ballot.php');
}else{
$_SESSION['fb'] = '<p style="color: red">Invalid Username/Password!</p>';
header('Location: home.php');
}
}else{
$_SESSION['fb'] = '<p style="color: red">Fill in all fields!</p>';
header('Location: home.php');
}
}
?>
我首先检查了查询是否真的在 mysql 上运行。有用。如果我正确输入了用户名和密码,就会有结果。但是当您登录时,即使用户名和密码正确与否,它也只是进入地址栏中带有 login.php 的空白页面。
这是为什么?