php 当仅有一条记录符合查询要求时,mysql_num_rows($result)总返回0。
问题代码如下:elseif(!empty($_POST['username'])&&!empty($_POST['userpw'])){$connect=mysql_co...
问题代码如下:
else if (!empty($_POST['username'])&&!empty($_POST['userpw'])) {
$connect=mysql_connect("localhost","zxs0225","zxs123") or die("Sorry,unable to connect the database.");
$select=mysql_select_db("mydatabase",$connect) or die("Sorry,unable to select the database.");
if(isset($select)) {echo "Ok! Database is connected.<br><br>";}
else echo "Error on connecting database.<br><br>";
$a=$_POST['username'];
$b=$_POST['userpw'];
$sql="SELECT * FROM people WHERE username='$a' AND password='$b'";
echo "$sql<br><br>";
$result=mysql_query($sql,$connect);
echo "mysql_query()函数的结果集:$result<br><br>";
if ($result){
$num=mysql_num_rows($result);
echo " 查询到的记录数量为:$num.<br><br>";
if ($num==1) echo "登录成功!<br><br>请返回上页继续阅读~";
else echo "信息错误!请检查您输入的信息!<br><br>返回上页重新输入~";
}
else echo "执行 $sql 错误:".mysql_error();
mysql_close($connect);
}
执行结果如下:
Ok! Database is connected.
SELECT * FROM people WHERE username='xxx' AND password='xxx'
mysql_query()函数的结果集:Resource id #4
查询到的记录数量为:0.
信息错误!请检查您输入的信息!
返回上页重新输入~ 展开
else if (!empty($_POST['username'])&&!empty($_POST['userpw'])) {
$connect=mysql_connect("localhost","zxs0225","zxs123") or die("Sorry,unable to connect the database.");
$select=mysql_select_db("mydatabase",$connect) or die("Sorry,unable to select the database.");
if(isset($select)) {echo "Ok! Database is connected.<br><br>";}
else echo "Error on connecting database.<br><br>";
$a=$_POST['username'];
$b=$_POST['userpw'];
$sql="SELECT * FROM people WHERE username='$a' AND password='$b'";
echo "$sql<br><br>";
$result=mysql_query($sql,$connect);
echo "mysql_query()函数的结果集:$result<br><br>";
if ($result){
$num=mysql_num_rows($result);
echo " 查询到的记录数量为:$num.<br><br>";
if ($num==1) echo "登录成功!<br><br>请返回上页继续阅读~";
else echo "信息错误!请检查您输入的信息!<br><br>返回上页重新输入~";
}
else echo "执行 $sql 错误:".mysql_error();
mysql_close($connect);
}
执行结果如下:
Ok! Database is connected.
SELECT * FROM people WHERE username='xxx' AND password='xxx'
mysql_query()函数的结果集:Resource id #4
查询到的记录数量为:0.
信息错误!请检查您输入的信息!
返回上页重新输入~ 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询