Home  >  Article  >  Backend Development  >  mysql_num_rows($result)总是等于0,为什么?解决方案

mysql_num_rows($result)总是等于0,为什么?解决方案

WBOY
WBOYOriginal
2016-06-13 13:29:321106browse

mysql_num_rows($result)总是等于0,为什么?急急
session_start();
$db=mysql_connect("localhost","root","205513")or die("unable to connect");
mysql_select_db("guanliku",$db)or die(mysql_error($db));
mysql_query("set names gb2312");
$name=(isset($_POST['name']))?trim($_POST['name']):'';
$password=(isset($_POST['passwrod']))?trim($_POST['password']):'';
$redirect=(isset($_REQUEST['redirect']))?$_REQUEST['redirect']:'tobiao.php';
if(isset($_POST['submit'])&&$_POST['submit']=='Login'){
$query='select access_level from cms_users
where '.'name="'.mysql_real_escape_string($name,$db).'"and 
'.'password=PASSWORD("'.mysql_real_escape_string($password,$db).'")';
$result=mysql_query($query,$db)or die(mysql_error($db));
if(mysql_num_rows($result)>0){
$_SESSION['name']=$name;
$_SESSION['logged']=1;
header('Refresh: 5; URL='.$redirect);
echo '

'.$name.'你将进入你自己的主页!

';
echo '

click here

';
}
else{
  $error='

不合法的用户名'.
  '密码!
点击'.'注册 如果你还没有注册

';
  }
  mysql_free_result($result);
  }
  ?>
 
 
  login
 
 
    if(isset($error)){
  echo $error;
  }
  ?>
 

 
 
 
 
 
 
 
 
 
 
 
 

 
 
 

 

 
 
  
  
  
 

------解决方案--------------------
echo $query;
将$query的结果放到数据查询工具运行下,看看结果是不是0.
------解决方案--------------------
$password=(isset($_POST['passwrod']))?trim($_POST['password']):'';
$password=(isset($_POST['password']))?trim($_POST['password']):'';

还是字母打错了。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn