为什么不管输入什么,每次都是跳转到http://localhost这个页面?<body>
<div align="center" class="STYLE1">
<p> </p>
<p>管理员登陆</p>
</div>
<form name="form1" method="post" action = " ">
<p align="center"> </p>
<p align="center"> </p>
<p align="center"><span class="STYLE2"><strong>管理员姓名</strong>:</span>
<input type="text" name="ad_name" />
</p>
<p align="center"> </p>
<p align="center"><span class="STYLE2">密码:</span>
<input type="password" name="ad_password" />
</p>
<p align="center"> </p>
<p align="center"><input type="submit" name="Submit" value="确定" /><input type="reset" name="Submit2" value="重置" /> </p>
</form>
<?php
if($_POST["Submit"]){
$name=$_POST["ad_name"];
$password=$_POST["ad_password"];
mysql_connect("localhost","root","ps") or
die("Could not connect:".mysql.error());
mysql_select_db("library");
$result=mysql_query("SELECT * FROM administrator WHERE ad_name='".$name."' and
ad_password='".$password."'");
$numrow=mysql_num_rows($result);
if($numrow<>0){
header("location:./welcome.html"); // 跳到管理员可以处理的界面
}
else{
header("location:./login.php");
}
mysql_close();
}
?><br />
<div align="center" class="STYLE1">
<p> </p>
<p>管理员登陆</p>
</div>
<form name="form1" method="post" action = " ">
<p align="center"> </p>
<p align="center"> </p>
<p align="center"><span class="STYLE2"><strong>管理员姓名</strong>:</span>
<input type="text" name="ad_name" />
</p>
<p align="center"> </p>
<p align="center"><span class="STYLE2">密码:</span>
<input type="password" name="ad_password" />
</p>
<p align="center"> </p>
<p align="center"><input type="submit" name="Submit" value="确定" /><input type="reset" name="Submit2" value="重置" /> </p>
</form>
<?php
if($_POST["Submit"]){
$name=$_POST["ad_name"];
$password=$_POST["ad_password"];
mysql_connect("localhost","root","ps") or
die("Could not connect:".mysql.error());
mysql_select_db("library");
$result=mysql_query("SELECT * FROM administrator WHERE ad_name='".$name."' and
ad_password='".$password."'");
$numrow=mysql_num_rows($result);
if($numrow<>0){
header("location:./welcome.html"); // 跳到管理员可以处理的界面
}
else{
header("location:./login.php");
}
mysql_close();
}
?><br />
if($_POST["Submit"]==$_POST["ad_password" and $_POST["ad_user")
header("Location: ./welcome.html"); // 跳到管理员可以处理的界面
}
else{
header("Location: ./login.php");
}
注意空格。
<body>
<?php
if($_POST["Submit"]==""){
?>
<div align="center" class="STYLE1">
<p> </p>
<p>管理员登陆</p>
</div>
<form name="form1" method="post" action = " ">
<p align="center"> </p>
<p align="center"> </p>
<p align="center"><span class="STYLE2"><strong>管理员姓名</strong>:</span>
<input type="text" name="ad_name" />
</p>
<p align="center"> </p>
<p align="center"><span class="STYLE2">密码:</span>
<input type="password" name="ad_password" />
</p>
<p align="center"> </p>
<p align="center"><input type="submit" name="Submit" value="确定" /><input type="reset" name="Submit2" value="重置" /> </p>
</form>
<?PHP
}ELSE{
$name=$_POST["ad_name"];
$password=$_POST["ad_password"];
mysql_connect("localhost","root","ps") or
die("Could not connect:".mysql.error());
mysql_select_db("library");
$result=mysql_query("SELECT * FROM administrator WHERE ad_name='".$name."' and
ad_password='".$password."'");
$numrow=mysql_num_rows($result);
if($numrow<>0){
header("location:./welcome.html"); // 跳到管理员可以处理的界面
}
else{
header("location:./login.php");
}
mysql_close();
}
?><br />
<form name="form1" method="post" action = " ">
改成
<form name="form1" method="post" action = "?">
mysql_select_db("library");
$result=mysql_query("SELECT * FROM administrator WHERE ad_name='".$name."' and
ad_password='".$password."'");
这两句对调一下,并把mysql_select_db("library")改成mysql_select_db("library",$result)