how to fix this query error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • simon2x1
    New Member
    • Dec 2008
    • 123

    how to fix this query error

    Warning: mysql_fetch_ass oc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\blo g\blogpost.php on line 11
    how can i fix thes error above this is my code
    Code:
    <?php
     class BlogPost  
     {  
    public $id;  
     public $title;  
     public $post;  
     public $author;
     if (!empty($inAuthorId))  
         {  
             $result = mysql_query("SELECT first_name, last_name FROM people WHERE id = " . $inAuthorId);  
             $row = mysql_fetch_assoc($result);  
    		$this->author = $row["first_name"] . " " . $row["last_name"];  
         }
    } 
    ?>
  • JKing
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    There could be several reasons for this.

    Have you connected to the mysql server and selected your database?

    Are you using the right field and table names?

    Modify your code as follows to get some more information on why the query is failing.
    Code:
    <?php
     class BlogPost  
     {  
    public $id;  
     public $title;  
     public $post;  
     public $author;
     if (!empty($inAuthorId))  
         {  
             $result = mysql_query("SELECT first_name, last_name FROM people WHERE id = " . $inAuthorId) or die(mysql_error());  
             $row = mysql_fetch_assoc($result);  
            $this->author = $row["first_name"] . " " . $row["last_name"];  
         }
    } 
    ?>

    Comment

    Working...