<?php $mylink = mysql_connect("localhost","cai","123") or die("连接服务器失败!"); mysql_select_db("kaoshi",$mylink) or die("连接数据库失败!"); $sql="select * from students where xhid='$user' and name='$pass'"; $result = mysql_query($sql,$mylink); if(mysql_num_rows($result)) { header("location:stdefault.php"); } else { header("location:jsdefault.php"); } ?>
mysql_query('select ...')只要传入的sql语句没有错误,它将始终返回一个资源句柄,换言之只有到发生mysql执行错误才会返回false。
大概你是想判断结果集是否为空,可以使用mysql_num_rows()函数
if(mysql_num_rows($result)>0)
{
header("location:stdefault.php");
}
else
{
header("location:jsdefault.php");
}
浏览器显示;select * from students where xhid='1' and name='clm'是显示字符啦!
难道这是我的sql语法错误?
if(!$result)
{
header("location:jsdefault.php");
}
else
{
header("location:stdefault.php");
}
$mylink = mysql_connect("localhost","cai","123") or die("连接服务器失败!");
mysql_select_db("kaoshi",$mylink) or die("连接数据库失败!");
$sql="select * from students where xhid='$user' and name='$pass'";
$result = mysql_query($sql,$mylink);
if(mysql_num_rows($result))
{
header("location:stdefault.php");
}
else
{
header("location:jsdefault.php");
}
?>