mysql_num_rows($result)总是等于0,为什么?解决方案
程序员文章站
2024-02-09 10:38:22
...
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 '
echo '';
}
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']):'';
还是字母打错了。
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 '';
}
else{
$error='
不合法的用户名'.
'密码! 请 点击'.'注册 如果你还没有注册
}
mysql_free_result($result);
}
?>
if(isset($error)){
echo $error;
}
?>
------解决方案--------------------
echo $query;
将$query的结果放到数据查询工具运行下,看看结果是不是0.
------解决方案--------------------
$password=(isset($_POST['passwrod']))?trim($_POST['password']):'';
$password=(isset($_POST['password']))?trim($_POST['password']):'';
还是字母打错了。
相关文章
相关视频
下一篇: 2009年数据库市场趋势预测