elite_prodigy Posted May 13, 2008 Share Posted May 13, 2008 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; } Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 13, 2008 Share Posted May 13, 2008 always use or die(): $query = mysql_query($sql,$conn) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 13, 2008 Share Posted May 13, 2008 I might actually explode if people don't try the OR die(mysql_error()) on the end of EVERY sql query. =/ Seriously. It's not a valid resource because the query failed. Quote Link to comment Share on other sites More sharing options...
elite_prodigy Posted May 13, 2008 Author Share Posted May 13, 2008 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 Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 13, 2008 Share Posted May 13, 2008 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.) Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 13, 2008 Share Posted May 13, 2008 I know, I've searched it once for a chuckle. It's actually quite disheartening, yet extremely hilarious. I'll try not to explode. =P Maybe evaporate, but certainly not explode. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.