Jump to content

[SOLVED] Not a valid result resource:


elite_prodigy

Recommended Posts

Can someone explain why the below code is NOT a valid result resource?

 

I use the variable $notice to store the array:

 

 
<?php

//...


case "home":{

  $sql = "SELECT `content` FROM `home` WHERE `site`=".$site.";";
  $query = mysql_query($sql,$conn);

  $area2 = $query;

  $sql = "SELECT * FROM `home_alerts` WHERE `site`=".$site.";";
  $query = mysql_query($sql,$conn);

  while($notice = mysql_fetch_array($query)){  //Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/expose/public_html/site/functions.php on line 30


   $title = $notice['title'];
   $content = $notice['content'];
   $author = $notice['added_by'];
   $time = $notice['added_on'];

   $area1 .= '<div class="alert"><h1 class="alert_title">{$title}</h1><div class="alert_content">{$content}</div><div class="author">Placed By: {$author}</div> <div class="date">On: {$time}</div></div>';

  } 

  break;
}

Link to comment
Share on other sites

Oh, thanks!

 

Right now I'm laughing my ass off at myself because that is EXACTLY what I programmed the page to do. I just havn't added in the clause that tells the user that the site doesn't exist which would prevent that error from ever even occuring!

 

Thanks. I have a bad habit of assuming my queries are perfect (they are not, mostly) and forgetting to put in the die() which, even when the queries are "perfect" might reveal information which could help fix the problem. (Which it almost always does)

 

Thanks!

 

--elite

Link to comment
Share on other sites

All code in a real applications, anything outside of a classroom (and if you want to get better than a C- in a class put in error checking, error reporting, and error recovery logic in your classroom work as well), must check for all possible errors that could occur before blindly accessing any data.

 

@DarkWater, I searched this forum for "result resource" in posts over the past 30 days. There were 4 pages of results. Some of these were just posts about result resources, but there were 62 posts that contain that error (some of this number are likely due to the yahoo's who needlessly quote what has already been posted). That leaves about two posts per day with the same error.

 

That such a common error gets posted, without people searching and finding what to do about it, is a sad situation. But, you have to look at the comic entertainment value of such posts to keep from going crazy or exploding (in your case.)

Link to comment
Share on other sites

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.