PHP prompts Warning: mysql_fetch_array() expects solution, expects_PHP tutorial

WBOY
Release: 2016-07-13 10:11:39
Original
1060 people have browsed it

php prompt Warning:mysql_fetch_array() expects solution, expects

The example in this article describes the solution to the php prompt Warning mysql_fetch_array() expects, and shares it with everyone for your reference. The specific analysis is as follows:

I encountered Warning when connecting to mysql database: mysql_fetch_array() expects... error message. According to my experience, this is because the query returned by sql is empty, and we used it directly without adding any judgment.

This is caused by the mysql_fetch_array() function. Let’s look at the solution together. My code is as follows:

Copy code The code is as follows:
include("conn.php");
if(!empty($_GET['id'])){
            $sql="select * from news where `id`='".$_GET['id']."'";
            $query=mysql_query($sql);
           $rs = mysql_fetch_array($query);                                          }
The prompt is wrong:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in F:xmappmylibrarysearch_result.php on line 32 Later I upgraded the code, the code is as follows:


Copy code The code is as follows:
if(!empty($_GET['id'])){
             $sql="select * from news where `id`='".$_GET['id']."'";
            $query=mysql_query($sql);
if( mysql_num_rows( $query )
{
            $rs = mysql_fetch_array($query);                                          }
else
{
mysql_error();

}

In this way, you will see the mysql error message. The result is that there is a problem with the sql statement. Just modify the sql statement.

Tip:

This type of error is caused by our non-standard grammar. If you want to deal with it, you can only output the sql one by one or process it in mysql_query(sql) or die(mysql_error()). in order to locate errors more accurately. I hope this article will be helpful to everyone’s PHP programming design.

http://www.bkjia.com/PHPjc/928214.html

truehttp: //www.bkjia.com/PHPjc/928214.htmlTechArticlephp prompt Warning: mysql_fetch_array() expects solution, expects This article describes the example of php prompt Warning mysql_fetch_array() expects The solution is shared with everyone for your reference...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!