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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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!

 

 

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.