<?php
$name=$_POST['name'];
$world=$_POST['world'];
if($name&&$world){
$mysql=mysql_connect("localhost","root","123456");
if(!$mysql){
echo "can‘t connect数据库连接失败";
exit;
}
$selected=mysql_select_db("test",$mysql);
if(!selected){
echo "con't select连接表出错";
exit;
}
$query="select * from auth where name=$name and passworld=$woeld";
$result=@ mysql_query($query,$mysql);
if(!$result){
echo "出错了";
}
exit;
}
?>
$result老是查不到结果
$name=$_POST['name'];
$world=$_POST['world'];
if($name&&$world){
$mysql=mysql_connect("localhost","root","123456");
if(!$mysql){
echo "can‘t connect数据库连接失败";
exit;
}
$selected=mysql_select_db("test",$mysql);
if(!selected){
echo "con't select连接表出错";
exit;
}
$query="select * from auth where name=$name and passworld=$woeld";
$result=@ mysql_query($query,$mysql);
if(!$result){
echo "出错了";
}
exit;
}
?>
$result老是查不到结果
if(!$result){ => if(!mysql_fetch_assoc($result)){
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US"><head>
<title> 验证登陆</title>
</head>
<body>
<?php
$name=$_POST['name'];
$world=$_POST['world'];
if($name&&$world){
$mysql=mysql_connect("localhost","root","123456");
if(!$mysql){
echo "can‘t connect数据库连接失败";
exit;
}
$selected=mysql_select_db("test",$mysql);
if(!selected){
echo "con't select连接表出错";
exit;
}
$query="select * from auth where name='".$name."'and passworld='".$world."'";
$result=@ mysql_query($query,$mysql);
if($result){
echo "欢迎您的到来";
}else{
echo "账号密码不匹配";
}
exit;
}
?>
<form action="secert.php" method="post">
<h1>Please Log In</h1>
<h2>This page is scert</h2>
<table>
<tr>
<td>Username</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="text" name="world"></td>
</tr>
<tr >
<td colspan="2" align="center" ><input type="submit" value="提交"></td></tr>
</table> </form>
</body></html>先在问题是怎么验证都是正确的。本来账号密码是name 123456 现在什么都能进的去
$result=@ mysql_query($query,$mysql);
if($result){
echo "欢迎您的到来";
}else{
echo "账号密码不匹配";
}这一小段改成下面的就可以了:$result=@ mysql_query($query,$mysql);
$re = mysql_fetch_object( $result );
if($re){
echo "欢迎您的到来";
}else{
echo "账号密码不匹配";
}
$re = mysql_fetch_array( $result );//读取结果集,有记录则返回当前指针指向的数据行(默认指向第一行),并将数据指针下移一行,否则返回false
if($re){
echo "欢迎您的到来";
}else{
echo "账号密码不匹配";
}
if($row[name]==$name && $row[world]==$world){
echo "欢迎您的到来";
}else{
echo "账号密码不匹配";
}