mysql_query查询结果为空
<?php2$uname=$_POST['uname'];3$upwd=$_POST['upwd'];4$servername="192.168.1.1";5$usern...
<?php
2 $uname=$_POST['uname'];
3 $upwd=$_POST['upwd'];
4 $servername = "192.168.1.1";
5 $username = "root";
6 $password = "密码";
7 $dbname = "数据库名";
8 $conn = mysql_connect($servername,$username,$password,$dbname);
9 if($conn){
10 $sql="select id,name,pwd from stu where name='".$uname."' and pwd='".$upwd."'";
11 $result = mysql_query($sql);
echo "$sql";
12 if(mysql_num_rows($result) > 0){
13 while($row = mysql_fetch_array($result)){
14 echo "id:".$row["id"]." - name:".$row["name"]." - password:".$row["pwd"]."<br/>";
15 echo "登陆成功,欢迎用户".$row["name"];
16 }
17 }else{
18 echo "登录失败";
19 }
20
21 }
22 mysql_close($conn);
23
24 ?>
页面返回结果
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /usr/local/httpd/htdocs/ht.php on line 13
登录失败
说明数据库连接是成功的,而且我使用11和12行中间的输出语句的输出结果登录数据库也查询成功了,请大神帮忙看看哪里出问题了 展开
2 $uname=$_POST['uname'];
3 $upwd=$_POST['upwd'];
4 $servername = "192.168.1.1";
5 $username = "root";
6 $password = "密码";
7 $dbname = "数据库名";
8 $conn = mysql_connect($servername,$username,$password,$dbname);
9 if($conn){
10 $sql="select id,name,pwd from stu where name='".$uname."' and pwd='".$upwd."'";
11 $result = mysql_query($sql);
echo "$sql";
12 if(mysql_num_rows($result) > 0){
13 while($row = mysql_fetch_array($result)){
14 echo "id:".$row["id"]." - name:".$row["name"]." - password:".$row["pwd"]."<br/>";
15 echo "登陆成功,欢迎用户".$row["name"];
16 }
17 }else{
18 echo "登录失败";
19 }
20
21 }
22 mysql_close($conn);
23
24 ?>
页面返回结果
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /usr/local/httpd/htdocs/ht.php on line 13
登录失败
说明数据库连接是成功的,而且我使用11和12行中间的输出语句的输出结果登录数据库也查询成功了,请大神帮忙看看哪里出问题了 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |