Jump to content

[SOLVED] Not sure what I'm missing here...


derekbelcher

Recommended Posts

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  ???

Link to comment
https://forums.phpfreaks.com/topic/153472-solved-not-sure-what-im-missing-here/
Share on other sites

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

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";

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.

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.

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.

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 :P

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 :P

haha, it was too .. see how much i actually pay attention.

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!

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.