derekbelcher Posted April 10, 2009 Share Posted April 10, 2009 I'm getting this error: Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/p2r71184/public_html/weblog.php on line 14 For this code: <?php mysql_connect("Localhost","p2r71184","692134a"); mysql_select_db("p2r71184"); $query ="SELECT title, description"; $query.=" DATE_FORMAT(entrydate, '%M %d, %Y') AS date"; $query.=" FROM upcoming ORDER BY entrydate DESC LIMIT 5"; $result= mysql_query($query); while (list($title,$description,$entrydate) = mysql_fetch_row($result)) { echo "<dt><b>$title ($entrydate)</b></dt>"; echo "<dd>$description</dd>"; } ?> Not sure what I'm missing. I have done this before and it worked, but I'm missing something. Please help ??? Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 10, 2009 Share Posted April 10, 2009 Try putting or die(mysql_error()); after your query... Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted April 10, 2009 Share Posted April 10, 2009 echo out $query, you'll see that you're missing a , in the string between description and DATE_FORMAT .. thus causing an incorrect query. Quote Link to comment Share on other sites More sharing options...
nankoweap Posted April 10, 2009 Share Posted April 10, 2009 your statement is failing. consider changing: DATE_FORMAT(entrydate, '%M %d, %Y') AS date to DATE_FORMAT(entrydate, '%M %d, %Y') AS entrydate jason Quote Link to comment Share on other sites More sharing options...
derekbelcher Posted April 10, 2009 Author Share Posted April 10, 2009 Thanks...Here is what I have changed based on the comments: I added a comma after description $query ="SELECT title, description,"; Then I changed the date to entrydate $query.="DATE_FORMAT(entrydate, '%M %d, %Y') AS entrydate"; The addition of "or die..." caused a parse error... As you can tell, I am a little new to this and learning as I go... Still get the same error though...it is something with this line (14) mysql_fetch_row($result)) { Thanks Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 10, 2009 Share Posted April 10, 2009 One problem is that your query is missing a comma in the SELECT list after description. Building your query by concatenating separate lines of php is going to make it kind of hard to see sql syntax problems among the php syntax. I would recommend just forming the query as one php statement (new lines and extra white space between parts of the sql is ignored) - $query ="SELECT title, description, DATE_FORMAT(entrydate, '%M %d, %Y') AS date FROM upcoming ORDER BY entrydate DESC LIMIT 5"; Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted April 10, 2009 Share Posted April 10, 2009 something is wrong with your query .. start by double-checking ALL the field names for spelling .. 9 times out of ten someone comes back saying, "Oops, i had 'entrydate' when it should've been 'entry_date'" .. not to say that's the problem, but just double-check those. Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted April 10, 2009 Share Posted April 10, 2009 The addition of "or die..." caused a parse error... $result= mysql_query($query) or die (mysql_error()); won't cause an error .. displays errors. Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 10, 2009 Share Posted April 10, 2009 something is wrong with your query .. start by double-checking ALL the field names for spelling .. 9 times out of ten someone comes back saying, "Oops, i had 'entrydate' when it should've been 'entry_date'" .. not to say that's the problem, but just double-check those. If there is a spelling mistake, it will fail and cause a mysql_error() anyway. That's why it's always good to use die() or trigger_error() after every query. You should really get into the habit of doing so. Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted April 10, 2009 Share Posted April 10, 2009 something is wrong with your query .. start by double-checking ALL the field names for spelling .. 9 times out of ten someone comes back saying, "Oops, i had 'entrydate' when it should've been 'entry_date'" .. not to say that's the problem, but just double-check those. If there is a spelling mistake, it will fail and cause a mysql_error() anyway. That's why it's always good to use die() or trigger_error() after every query. You should really get into the habit of doing so. ya, but he's not using any error reporting .. it's already been suggested. Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 10, 2009 Share Posted April 10, 2009 something is wrong with your query .. start by double-checking ALL the field names for spelling .. 9 times out of ten someone comes back saying, "Oops, i had 'entrydate' when it should've been 'entry_date'" .. not to say that's the problem, but just double-check those. If there is a spelling mistake, it will fail and cause a mysql_error() anyway. That's why it's always good to use die() or trigger_error() after every query. You should really get into the habit of doing so. ya, but he's not using any error reporting .. it's already been suggested. Yeah, by me Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted April 10, 2009 Share Posted April 10, 2009 something is wrong with your query .. start by double-checking ALL the field names for spelling .. 9 times out of ten someone comes back saying, "Oops, i had 'entrydate' when it should've been 'entry_date'" .. not to say that's the problem, but just double-check those. If there is a spelling mistake, it will fail and cause a mysql_error() anyway. That's why it's always good to use die() or trigger_error() after every query. You should really get into the habit of doing so. ya, but he's not using any error reporting .. it's already been suggested. Yeah, by me haha, it was too .. see how much i actually pay attention. Quote Link to comment Share on other sites More sharing options...
derekbelcher Posted April 10, 2009 Author Share Posted April 10, 2009 o.k. I'm an idiot. For real. I wasn't putting the "die" statement in the right place. I read the post again and realized that....I'm an idiot. When I put the "die" in, guess what????? I didn't select the flippin' database. Great tips though that I will use in the future. I absolutely love PHP...love this site cause there are some real "professional" attitudes and help here. Thanks everyone...until next time! Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 10, 2009 Share Posted April 10, 2009 Ahahaha Congratulations. 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.