各位大侠,我做了一个简答的登录窗口,代码如下,可是现在状况是:只要一打开此网页,即弹出“用户名和密码错误”,我想知道,代码那里出了逻辑问题,希望指点,我是菜鸟,希望能用详细的语言给讲讲。
谢谢
分不多了,不好意思,只能给20分了。<html>
<head>
<title></title>
<style type="text/css">
body{padding:0;margin:0;}
body,html{height:100%;}
#outer{height:100%;overflow:hidden;position:relative;width:100%;background:#555;}
#outer[id]{display:table;position:static;}
#middle{position:absolute;top:50%;left:400;}
#middle[id]{display;table-cell;vertical-align;middle;position:static;}
#inner{position:relative;top:-50%;margin:0 auto;}
#content{width:70%;height:80%;border:1px solid red;background=#eee;margin:0 auto;}
</style>
</head>
<body>
<form method="post" action="index.php" name="send" onsubmit="return chkfields()">
<center>
<div id="outer">
<div id="middle">
<div id="inner">
<div id="content">
<br>
用户:
<input type="text" size="21" name="name">
<br>
<br>
密码:
<input type="password" size="22" name="passwd">
<br>
<br>
<input type="submit" value="确  认" name="a1">
         
<input type="button" onClick="window.close()"; value="取  消">
<br>
<br>
<br>
                 
<?php
$zhou=array("日","一","二","三","四","五","六");
$xingqi=date("w");//星期用“w”表示
echo date("Y年m月d日 H:i:s 星期$zhou[$xingqi]");
?>
</div>
</div>
</div>
</div>
</center>
</form>
<script type="text/javascript">
function chkfields()
{
if(document.send.name.value=="")
{
window.alert("用户名不能为空")
return false
}
if(document.send.passwd.value=="")
{
window.alert("密码不能为空")
return false
}
return true
}
</script>
</body>
</html>
<?php
$submit=$_POST["a1"];
$dengluming=$_POST['name'];
$denglumima=$_POST['passwd'];
@ $db=mysqli_connect('localhost','root','password','test');
$sql="select * from denglu where name='".$dengluming."' and password='".$denglumima."'";
$re=mysqli_query($db,$sql);
$row=mysqli_num_rows($re);
if ($row)
{
$_SESSION["name"]=$dengluming;
$_SESSION["password"]=true;
echo "<script>window.location.href='main.php'</script>";
}
else
{
echo "<script>alert('用户名和密码不能为空');</script>";
}
?>
谢谢
分不多了,不好意思,只能给20分了。<html>
<head>
<title></title>
<style type="text/css">
body{padding:0;margin:0;}
body,html{height:100%;}
#outer{height:100%;overflow:hidden;position:relative;width:100%;background:#555;}
#outer[id]{display:table;position:static;}
#middle{position:absolute;top:50%;left:400;}
#middle[id]{display;table-cell;vertical-align;middle;position:static;}
#inner{position:relative;top:-50%;margin:0 auto;}
#content{width:70%;height:80%;border:1px solid red;background=#eee;margin:0 auto;}
</style>
</head>
<body>
<form method="post" action="index.php" name="send" onsubmit="return chkfields()">
<center>
<div id="outer">
<div id="middle">
<div id="inner">
<div id="content">
<br>
用户:
<input type="text" size="21" name="name">
<br>
<br>
密码:
<input type="password" size="22" name="passwd">
<br>
<br>
<input type="submit" value="确  认" name="a1">
         
<input type="button" onClick="window.close()"; value="取  消">
<br>
<br>
<br>
                 
<?php
$zhou=array("日","一","二","三","四","五","六");
$xingqi=date("w");//星期用“w”表示
echo date("Y年m月d日 H:i:s 星期$zhou[$xingqi]");
?>
</div>
</div>
</div>
</div>
</center>
</form>
<script type="text/javascript">
function chkfields()
{
if(document.send.name.value=="")
{
window.alert("用户名不能为空")
return false
}
if(document.send.passwd.value=="")
{
window.alert("密码不能为空")
return false
}
return true
}
</script>
</body>
</html>
<?php
$submit=$_POST["a1"];
$dengluming=$_POST['name'];
$denglumima=$_POST['passwd'];
@ $db=mysqli_connect('localhost','root','password','test');
$sql="select * from denglu where name='".$dengluming."' and password='".$denglumima."'";
$re=mysqli_query($db,$sql);
$row=mysqli_num_rows($re);
if ($row)
{
$_SESSION["name"]=$dengluming;
$_SESSION["password"]=true;
echo "<script>window.location.href='main.php'</script>";
}
else
{
echo "<script>alert('用户名和密码不能为空');</script>";
}
?>
if(isset($_POST['dengluming'] && isset($_POST['denglumima']))){
....
}
if($_SERVER['REQUEST_METHOD'] != "POST") return;//加上这个
$submit=$_POST["a1"];
$dengluming=$_POST['name'];
$denglumima=$_POST['passwd'];
@ $db=mysqli_connect('localhost','root','password','test');
$sql="select * from denglu where name='".$dengluming."' and password='".$denglumima."'";
$re=mysqli_query($db,$sql);
$row=mysqli_num_rows($re);
if ($row)
{
$_SESSION["name"]=$dengluming;
$_SESSION["password"]=true;
echo "<script>window.location.href='main.php'</script>";
}
else
{
echo "<script>alert('用户名和密码不能为空');</script>";
}
?>
else
{
echo "<script>alert('用户名和密码错误');</script>";
}
?>
kyzy_yy_pm 你好 我按照你的指点,把代码改为如下:<?php
//if ($_SERVER['REQUEST_METHOD']!="post") return ;
if (isset($_POST['dengluming']) && isset($_POST['denglumima']))
{
$submit=$_POST["a1"];
$dengluming=$_POST['name'];
$denglumima=$_POST['passwd'];
@ $db=mysqli_connect('localhost','root','password','linglong');
$sql="select * from denglu where name='".$dengluming."' and password='".$denglumima."'";
$re=mysqli_query($db,$sql);
$row=mysqli_num_rows($re);
if ($row)
{
$_SESSION["name"]=$dengluming;
$_SESSION["password"]=true;
echo "<script>window.location.href='main.php'</script>";
}
else
{
echo "<script>alert('用户名和密码不能为空');</script>";
}
}
?>也是打开网页不出现提示了,但是输入错误的账号和密码也不出现提示,我想要输入错误账号和面能够出现提示...
$submit=$_POST["a1"];
$dengluming=$_POST['name'];
$denglumima=$_POST['passwd'];