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

Exception or error:

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

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

<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

How to solve:

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

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().


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

Leave a Reply

Your email address will not be published. Required fields are marked *