php 警告:mysql_fetch_array():在第 40 行中提供的参数不是有效的 MySQL 结果

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14048170/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:31:11  来源:igfitidea点击:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL Result in line 40

phphtmlmysql

提问by TheWhiteHatter

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

可能重复:
mysql_fetch_array() 期望参数 1 是资源,选择中给出的布尔值

i keep getting the error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL Result in line 40 on my webpage i dont know why.. please help me . Background: this script is to pull my database tables up named yname,username,password,date,comments,works,dworks the works and dworks are for people who tryed what came up and then they can judge if it works - yes it works dworks - no it dosent work its supposed to be voting sortof well forget about that my problem is on like 40 of this script please help me

我不断收到错误警告:mysql_fetch_array(): 提供的参数不是有效的 MySQL 结果在我的网页第 40 行我不知道为什么..请帮助我。背景:这个脚本是把我的数据库表拉起来命名为 yname、用户名、密码、日期、评论、作品、dworks 作品和 dworks 是为那些尝试过的人准备的,然后他们可以判断它是否有效 - 是的,它有效 dworks - 不,它没有工作它应该投票有点忘了我的问题是这个脚本的 40 请帮助我

<php require "br.htm" ?>
<style>
<?php require "styles.css" ?>
</style>
<?php

$host="host"; // Host name 
$username="name"; // Mysql username 
$password="pass"; // Mysql password 
$db_name="dbname"; // Database name 
$tbl_name="passes"; // Table name 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// select record from mysql 
$sql="SELECT * FROM $tbl_name order by id desc";
$result=mysql_query($sql);
?>
<table background='https://lh6.ggpht.com/DFABQFuYSXLBiB6qlvDPfOONOUxCiwM6_S-dHnjW82iognQToTkORsy7RVXsAz0Y23w=w705' width='50%'>
<tr>
<th align='center'>Submition By</th><th align='center'>ScreenName</th><th align='center'>Password</th><th align='center'>Does This Work?</th>
</tr>
<tr>
<th align='center'>
<hr color='lime' width='100%'/>
</th>
<th align='center'>
<hr color='lime' width='100%'/>
</th>
<th align='center'>
<hr color='lime' width='100%'/>
</th>
<th align='center'>
<hr color='gold' width='100%'/>
</th>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>

<tr>
<td background='transparent' align='left'><i><b><? echo $rows['yname']; ?> </b></i></td>
<td background='transparent' align='center'><i><b><? echo $rows['username']; ?></b></i></td>
<td background='transparent' align='right'><i><b><? echo $rows['password']; ?></b></i></td>
<td background='transparent' align='right'><i><b>&nbsp;&nbsp;&nbsp;Yes<? echo $rows['works']; ?></b></i></td>
</tr>

<?php
// close while loop 
}
?>

</table>

<?php
// close connection; 
mysql_close();
?>
<center> 

i dont want to re-style the page but if i have to i will.. if you see what is wrong please make a post below and tell me what line its on and how to correct it please then ill come back and let u know if it works :) thank you

我不想重新设计页面的样式,但如果必须的话,我会的。如果它有效:)谢谢

回答by MrCode

This error means your query failed. mysql_query()returns falseif an error occurred, you are then passing falseto mysql_fetch_array()which is triggering the error message.

此错误意味着您的查询失败。如果发生错误,则mysql_query()返回false,然后您将传递falsemysql_fetch_array()触发错误消息的哪个。

Your query could be failing due to a missing/wrong table or field. To see the detailed error, print out the result of mysql_error().

由于缺少/错误的表或字段,您的查询可能会失败。要查看详细错误,请打印结果mysql_error()



The mysql_*library is deprecated. It is recommended to upgrade to MySQLi or PDO.

mysql_*库已弃用。建议升级到 MySQLi 或 PDO。