您好,当用户输入错误的用户名或密码时,我正在做小型登录表单,它重定向到登录页面,但在我的脚本标题功能不起作用
这是 logging.php 页面
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js"></script>
<style type="text/css">
* { font-family: Verdana; font-size: 96%; }
label { width: 10em; float: left; }
label.error { float: none; color: red; padding-left: .5em; vertical-align: top; }
p { clear: both; }
.submit { margin-left: 12em; }
em { font-weight: bold; padding-right: 1em; vertical-align: top; }
</style>
<script>
$(document).ready(function(){
$("#commentForm").validate();
});
</script>
</head>
<body>
<form class="cmxform" enctype="multipart/form-data" id="commentForm" method="post" action="buy.php">
<fieldset>
<legend>A simple comment form with submit validation and default messages</legend>
<p>
<label for="cname">Name</label>
<em>*</em><input id="name" name="name" size="25" class="required" minlength="2" />
</p>
<p>
<label for="cemail">Password</label>
<em>*</em><input id="password" type="password" name="password" size="25" class="required" />
</p>
<p> </p>
<p> </p>
<p>
<input class="submit" type="submit" value="login"/>
</p>
</fieldset>
</form>
</body>
</html>
这是登录后的buy.php页面,它转到此页面
<?php
session_start();
$Name = $_POST['name'];
$Pass = $_POST['password'];
//STEP 1 Connect To Database
$host= "localhost";
$dbname= "register";
$user = "root";
$pass = "";
try {
# MySQL with PDO_MYSQL
$DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
//$DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$STH = $DBH->query("SELECT username, password from tbl_users");
$STH->execute();
//STEP 2 Declare Variables
$Query = $DBH->query("SELECT * FROM tbl_users WHERE username='$Name' AND password='$Pass'");
$Query->execute();
$Query->setFetchMode(PDO::FETCH_NUM);
$NumRows = $Query->fetch();
$_SESSION['name'] = $Name;
$_SESSION['password'] = $Pass;
//STEP 3 Check to See If User Entered All Of The Information
if(empty($_SESSION['name']) || empty($_SESSION['password']))
{
die("could not connect");
}
if($Name && $Pass == "")
{
die("Please enter a name and password!");
}
if($Name == "")
{
die("Please enter your name!" . "</br>");
}
if($Pass == "")
{
die("Please enter a password!");
echo "</br>";
}
//STEP 4 Check Username And Password With The MySQL Database
if($NumRows != 0)
{
$STH->setFetchMode(PDO::FETCH_ASSOC);
while($Row = $STH->fetch())
{
$dname = $Row['username'];
$dpass = $Row['password'];
}
}
else
{
die("Incorrect Username or Password!");
if( $_SESSION['name']!= $dname || $_SESSION['password'] != $dpass)
{
header("location: login.php");
}
else
{
header("location: http://www.google.com");
}
}
if($Name == $dname && $Pass == $dpass)
{
// If The User Makes It Here Then That Means He Logged In Successfully
echo "Hello " . $Name . "!";
}
}
catch(PDOException $e) {
echo "I'm sorry, Dave. I'm afraid I can't do that.";
$e->getMessage();
}
?>
<html>
<body>
<p>Here is where you can put information for the user to see when he logs on. (Anything inside these html tags!)</p>
</body>
</html>