Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 这个警告不知道怎么解决mysql_fetch_array() expects parameter 1 to be resource

这个警告不知道怎么解决mysql_fetch_array() expects parameter 1 to be resource

Jun 23, 2016 pm 02:22 PM

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /data/multiserv/users/983917/projects/2245004/www/view.php on line 42

本地服务器调试没有出现这个警告,上传到远程服务器就出现了...而且我没有权限修改远程服务器的配置..只能从代码这里来解决

view.php

 PHP<?phpinclude("conn.php");$ID=$_GET['id'];$ID=ceil($ID);$sql="select * from dianpu where id_dian='$ID' and access='1'";$query=mysql_query($sql,$mylink);$result=mysql_fetch_array($query);?><title></title><table width="891" height="387" border="1" align="center">  <tr>    <th scope="col">店铺名字</th>    <th width="787" scope="col"><?php echo $result['dian_name'];?></th>  </tr>  <tr>    <td width="88"><div align="center">电话</div></td>    <td>      <div align="center">        <?phpecho $result['dian_phone'];?>    </div></td>  </tr>  <tr>    <td><div align="center">      <p>食客评分(0~10)    </p>    </div></td>    <td><div align="center"><?php 	$levelsql="select * from comment where id_dian='$ID'";	$query2=mysql_query($levelsql,$mylink);		//取出总分	$levelcount="select count(*) as count from comment where id_dian='$ID'";	$levelquery=mysql_query($levelcount,$mylink);	$result5=mysql_fetch_array($levelquery);	//取出评分人数	$i=0;	$zongfen=0;	$row=mysql_fetch_array($query2);	do	{	$zongfen=$zongfen+$row['level'];		}	while($row=mysql_fetch_array($query2));	$level=$zongfen/$result5['count'];	echo "平均分:  ".$level;	echo "</br>";	echo "评分个数:".$result5['count'];	?></div></td>  </tr>  <tr>    <td><div align="center">菜单</div></td>    <td><p align="center">      <?php	$sql2="select * from menu where id_dian='$ID' and access='1'";	$result2=mysql_query($sql2,$mylink);	$result3=mysql_fetch_array($result2);	$i=1;	if(!$result3){echo "暂无菜单";}else{	do	{	echo $result3['menuname']."  ¥".$result3['price'];	echo "</br>";	$i++;	}	while($result3=mysql_fetch_array($result2))	;}?>      </p>    <p> </p></td>  </tr>  <tr>    <td><div align="center">备注</div></td>    <td><div align="center"><?php echo $result['beizhu'];?></div></td>  </tr>  <tr>    <td><div align="center">食客评价</div></td>    <td><div align="left">      <?php 	  $comment="select * from comment where id_dian='$ID'";	$commentquery=mysql_query($comment,$mylink);	  $result4=mysql_fetch_array($commentquery,$mylink);	  if($result4)	  {	$i=1;	do{	echo $i."楼--".$result4['username'].": ".$result4['comment']."</br>";	$i++;	}	while($result4=mysql_fetch_array($commentquery,$mylink));	  }	  else	  {		  echo "暂无评论,我们期待你的参与";		  		  }	?>    </div></td>  </tr>  <tr>    <td><div align="center">      <p>给店家</p>      <p>评分评价</p>    </div></td>    <td><form name="form1" method="post" action="comment.php">      <label for="textfield"></label>      <div align="center">        <p>          <label for="name"></label>          昵称          <input type="text" name="name" id="name" />        </p>        <p>评论          <textarea name="pinglun" rows="5" id="pinglun"></textarea>        </p>        <p>          <label for="level"></label>          <label for="level">分数</label>          <select name="level" id="level">            <option value="1">1</option>            <option value="2">2</option>            <option value="3">3</option>            <option value="4">4</option>            <option value="5">5</option>            <option value="6">6</option>            <option value="7">7</option>            <option value="8">8</option>            <option value="9">9</option>            <option value="10">10</option>          </select>           分          <input type="hidden" name="gengxin" value="<?php echo $ID;?>" id="pinglun">          <input type="submit" name="button" id="button" value="提交">        </p>      </div>    </form></td>  </tr></table><p align="center"><a href="view.php?id=<?php echo $ID-1;?>">上一间</a> ///  <a href="view.php?id=<?php echo $ID+1;?>">下一间</a></p>
Copy after login


回复讨论(解决方案)

本地调试的apache已经display_error=on  没有出现这个警告

42行是哪行?一般情况下加个or die 会有提示.
mysql_query($comment,$mylink)  or die(mysql_error());

 $result5=mysql_fetch_array($levelquery);
 $result4=mysql_fetch_array($commentquery,$mylink);
 $result3=mysql_fetch_array($result2);

有mysql_fetch_array的都报错了

42行是哪行?一般情况下加个or die 会有提示.
mysql_query($comment,$mylink) or die(mysql_error());

贴出改成 #2 后的错误信息 

include("conn.php");//这行下边加入
echo $mylink; //贴出结果

我怀疑数据库没有连接成功

出来的是resource id #1不知道代表什么 include("conn.php");//这行下边加入
echo $mylink; //贴出结果
我怀疑数据库没有连接成功

#2就是从原码里弄出来的。。不太明白你意思 贴出改成 #2 后的错误信息

结贴了..看来粗心大意要不得啊..我忘记把数据库给同步过去了.... 出来的是resource id #1不知道代表什么引用 5 楼  的回复:
include("conn.php");//这行下边加入
echo $mylink; //贴出结果
我怀疑数据库没有连接成功

这个东i还是姐ue不了

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

What are Enumerations (Enums) in PHP 8.1? What are Enumerations (Enums) in PHP 8.1? Apr 03, 2025 am 12:05 AM

The enumeration function in PHP8.1 enhances the clarity and type safety of the code by defining named constants. 1) Enumerations can be integers, strings or objects, improving code readability and type safety. 2) Enumeration is based on class and supports object-oriented features such as traversal and reflection. 3) Enumeration can be used for comparison and assignment to ensure type safety. 4) Enumeration supports adding methods to implement complex logic. 5) Strict type checking and error handling can avoid common errors. 6) Enumeration reduces magic value and improves maintainability, but pay attention to performance optimization.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

See all articles