Home  >  Article  >  Backend Development  >  Warning: mysql_fetch_array() expects parameter 1,该如何解决

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

WBOY
WBOYOriginal
2016-06-13 13:43:291281browse

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);
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn