resource(4) of type (mysql result) $res=mysql_query($sql,$conn); //LZ在这里var_dump($res),只要是显示resource(4) of type (mysql result)就对了 //如果不是那就是之前数据库连接或者内容上的问题了吧 if ($row=mysql_fetch_row($res)){
引发错误的不是数据库操作,而是 $id=$_post['id']; $password=$_post['password']; 应为 $id=$_POST['id']; $password=$_POST['password']; 注意,php的变量时大小写敏感的由于并不存在 $_post 数组,而你又屏蔽了 NOTICE 级别的错误(不然早就发现了) 于是 $sql="select password from admin where id=$id"; 变成了 $sql="select password from admin where id="; 显然是错误的! 因此导致 Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource 的出现
mysql_fetch_row()这条语句中的参数(也就是$res)必须是MYSQL返回的资源类型才行。
普通的自定义数组、PHP变量应该是不行的。
if($row = mysql_fetch_row($res))这句话是可以用的。
这是错误信息
比如 你在数据库读取的时候
$a = mysql_query();
mysql_fetch_row($a);
这样才好用吧
<?php $id=$_post['id'];
$password=$_post['password']; $conn=mysql_connect("localhost","root","1234")or die("连接失败".mysql_errno());
mysql_select_db("test",$conn)or die("选择数据库失败".mysql_errno());
mysql_query('set names utf8') or die("设置编码失败".mysql_errno());
$sql="select password from admin where id=$id";
$res=mysql_query($sql,$conn);
if ($row=mysql_fetch_row($res)){
if ($row[1]==$password){
header('location:empMain.php');
exit();
}
}
header('location:login.php');
exit();
mysql_free_result($res);
mysql_close();
?>
$res=mysql_query($sql,$conn);
//LZ在这里var_dump($res),只要是显示resource(4) of type (mysql result)就对了
//如果不是那就是之前数据库连接或者内容上的问题了吧
if ($row=mysql_fetch_row($res)){
$id=$_post['id'];
$password=$_post['password'];
应为
$id=$_POST['id'];
$password=$_POST['password'];
注意,php的变量时大小写敏感的由于并不存在 $_post 数组,而你又屏蔽了 NOTICE 级别的错误(不然早就发现了)
于是
$sql="select password from admin where id=$id";
变成了 $sql="select password from admin where id=";
显然是错误的!
因此导致
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource
的出现