数据库报错:mysql_fetch_array()expects parameter 1 to br resource,

源码如下:

if($_POST["action"]=="do")
{
$xh=$_POST["xh"];
$pwd=$_POST["pwd"];
session_start();
include("db_conn.php");
$result=mysql_query("select count(*) from user where xh='$xh' and pwd='".md5($pwd)."'");
$row=mysql_fetch_array($result);

if($row[0]==0)
{
echo("");
exit();
}

else
{
$_SESSION["xh"]=$xh;
echo ("");
exit();
}
}

?>
当前问题共有如下(1)个解决方案
  • 橙醉骑士团
    橙醉骑士团

    1、先判断数据库是否连接上db_conn.php 里面可能 连接失败

    2、这个错误还有可能是没传 参数,导致$SQL语句缺失 不合法,所以函数

    $sql = "select count(*) from user where xh='$xh' and pwd='".md5($pwd)."'";
    echo $sql;
    mysql_query($sql);

    3、如果以上你一点都看不懂,建议看看PHP基础再来。

    4、从mysql_query这个函数的使用上,可以判断你的代码很有些年份了,2013年已经废弃了这个函数。在工程师看来 = 垃圾代码。。。如果是初学者建议 你不要再学这个教材了

上一篇:为什么说php配mysql好?直接用php去服务器硬盘里提数据不就行了吗?为什么要用mysql?
下一篇:如何开启MySQL远程访问权限 允许远程连接