Jump to content

Warning: Mysql_Fetch_Assoc() Expects Parameter 1 To Be Resource, Boolean Given In C:\wamp\www\login.php On Line 181


Recommended Posts

help me sir... Am a newbie in these programming....

 

i gotto submit this project by today evening :(

ma whole diwali is being messed up by these...

 

Am attachin the file with it.... plz help me... i donnow how to let it work....

 

plz help me sir... i'll b so thankful... as itz d last date for submission n ma practical exam :(

login.php

You are storing the result of the query in the variable $result. However, the query is failing, so $result is set to the Boolean FALSE value. On line 181 you then try to "use" the result of the query by extracting a row from the result

while($row = mysql_fetch_assoc($result))

 

As stated above, since the query failed $result does not contain a resource (pointer) to a query result.

 

You should always check your queries to see if they fail. If they do you should output the MySQL error and the actual query to the page for debugging purposes. In this case I see a few problems.

 

1. I'm not certain, but I don't think != is valid in MySQL. You should use <>

2. This is not valid

if($result > 0){

I'm pretty sure you want to check if the result contained more than 0 ROWS. As stated above $result will contain a resource to the result set - it is not the count of the records returned. Instead you would do this:

if(mysql_num_rows($result) > 0){

 

Use the following

$sql = "SELECT *
    FROM members
    WHERE confirmation = '1'
	  AND type <> 'Admin'
	  AND image <> 'uploads/propic.jpg'
    ORDER BY RAND() LIMIT 9";
$result = mysql_query($sql);
if(!$result)
{
   echo "The query failed. Query: {$sql}<br>Error: " . mysql_error();
}
elseif(!mysql_num_rows($result))
{
   echo "There were no records returned.";
}
else
{
   //Display the results
   $first = $row['image'];

Two quick notes:

 

1. The != operator is valid in MySQL, although <> is preferred.

2. Depending on the size of your MySQL table, using ORDER BY RAND() can be very slow. If your table is not large (more than 500+ rows about), then you really do not have to worry. However, using ORDER BY RAND() is a bad habit to get into.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.