Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts

    mysql_fetch_object(): error

    I have an error displaying as
    Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /homepages/18/d152801671/htdocs/Crowds_Design/CDblog/Admin/inc/clist.php on line 16
    Line 16 is where I have a while loop.
    PHP Code:
    <?php
    error_reporting 
    (E_ALL);

    require 
    '../Connections/CDblog.php';

    // Connect to the database
    mysql_connect($hostname_CDblog,$username_CDblog,$password_CDblog) or die(mysql_error());
    mysql_select_db($database_CDblog) or die(mysql_error());
    $area '4';
    echo 
    "this is the area selected $area";
    $query="SELECT id, name, email, url, message, title_art"
    "FROM CDblg_comments".
    "WHERE title_art = '$area'" or die(mysql_error());
    $sql "SELECT * FROM CDblg_comments ORDER BY id DESC LIMIT 150" or die(mysql_error());
    $result mysql_query($sql); 
    while (
    $record mysql_fetch_object($result)) {
    ?>

    <a href="?q=edit&id=<? echo "$record->id"?>">update</a> | <a href="" onClick="return confirm('remove (<? echo "$record->id"?>)?')">delete</a>
    &nbsp;&nbsp;&nbsp;<b><? echo "$record->id"?></b></font><p></p>
    <?
      

    ?>
    And my sql table for CDblog_comments is

    id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    name VARCHAR(30) NOT NULL,
    email VARCHAR(50) NOT NULL,
    url VARCHAR(50) NULL,
    message TEXT NOT NULL,
    entry_date DATE NOT NULL,
    ip VARCHAR (30) NOT NULL,
    title_art VARCHAR (100) NOT NULL default '',
    PRIMARY KEY(id)
    I have used something very similar for another table and it works just fine...
    Can anyone spot where I am going wrong ?

    Crowds
    PHP magpie | And President Of The Marmalade Atkins Fan Club | Crowds Design

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    you attempted to put in error checking, but did it in the wrong place:
    PHP Code:
    $sql "SELECT * FROM CDblg_comments ORDER BY id DESC LIMIT 150" or die(mysql_error()); 
    If assigning variables fails, then there's something seriously wrong. You want this on the next line:
    PHP Code:
    $result mysql_query($sql) or die(mysql_error()); 
    Echoing out the actual query that's being sent can be immensely useful,lets you see any problems brought in by the PHP.

    In your case, it looks like the splitting of the query over multiple lines will result in the words being joined together:
    PHP Code:
    "FROM CDblg_comments"
    "WHERE title_art = '$area'" or die(mysql_error()); 
    Try putting in spaces at the srtart of the lines, mysql won't understand 'CDblg_commentsWHERE"

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks GJay,
    I made the changes and the new mysql error report gave me something to work with....
    The table CDblg_comments Does not exsist.
    Doh
    Thats because it's called CDblog_comments !
    Sometimes I guess I should just walk away for a few hours.
    Wood for the tree's and all that

    Thanks again GJay !

    Crowds
    PHP magpie | And President Of The Marmalade Atkins Fan Club | Crowds Design


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •