>백엔드 개발 >PHP 튜토리얼 >Warning: mysql_fetch_array() expects parameter 1,该如何解决

Warning: mysql_fetch_array() expects parameter 1,该如何解决

WBOY
WBOY원래의
2016-06-13 10:12:371087검색

Warning: mysql_fetch_array() expects parameter 1
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/kxmusic/test.php on line 8


本人使用XAMPP for linux 版
在本地机 WAMP 可以使用
但上次到服务器 就出现这个错误
请指教一下 


PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php 02  include("config.php");  03    04   if($_POST[submit]){  05     $username= str_replace(" ","",$_POST[username]);  06     $_SESSION[login_name]= str_replace(" ","",$_POST[username]);  07     $sql="select * from user_list where `username` = '$username' and user_static != '0'";  08     $query=mysql_query($sql);  09     $us=is_array($row=mysql_fetch_array($query));  10     $ps= $us ? md5($_POST[password].ALL_PS)== $row[password] : FALSE;  11     if($ps){  12         $_SESSION[uid]=$row[uid];  13         $_SESSION[user_shell]=md5($row[username].$row[password].ALL_PS);  14         $_SESSION[times]=mktime();  15         echo "登陆成功";  16         echo "<a href=\"jianli.php\">add list<br>";  17         echo "<a href="%5C%22logout.php%5C%22">logout</a>";  18     }else{  19         echo "密码或者用户名错误";  20          session_destroy();  21     }  22    23   }  24    25    26    27 ?>  28 <link href="common.css" type="text/css" rel="stylesheet">  29    30   <title>::开心肠粉网::开心音乐室</title>
31 32 username:
33 password:
34 code: 35 Warning: mysql_fetch_array() expects parameter 1,该如何解决 36

37 38


config.php 
PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php 02  session_start();  03  //数据库连接  04  $conn=mysql_connect('localhost','root','');  05  mysql_select_db('test',$conn);  06  mysql_query("set names 'gbk'");   07  //定义常量  08  define(ALL_PS,"topbase");  09    10   function user_shell($uid,$shell,$m_id){  11     $sql="select * from user_list where `uid` = '$uid'";  12     $query=mysql_query($sql);  13     $us=is_array($row=mysql_fetch_array($query));  14     $shell=$us ? $shell==md5($row[username].$row[password].ALL_PS):FALSE;  15     if($shell){  16         if($row[m_id]<=$m_id){  17            return $row;  18         }else{  19         echo "你的权限不足";  20         exit();  21         }  22     }else{  23      echo "你无权限访问该页";  24      exit();  25     }  26   }  27    28     function user_mktime($onlinetime){  29     $new_time = mktime();  30     echo $new_time-$onlinetime;  31     if($new_time-$onlinetime > '1000'){  32     echo "登录超时";  33     exit();  34     session_destroy();  35    }else{  36     $_SESSION[times]=mktime();  37    }  38   }  39  ?> 


------解决方案--------------------
var_dump($query); //这里显示什么
$row=mysql_fetch_array($query);
------解决方案--------------------
query返回结果不正确。应该是一个对象,
$query=mysql_query($sql) or die(mysql_error());

把错误模式打开,这样就不会有这样的问题了,因为你的错误提示等级太高了!

探讨
var_dump($query);
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.