PDA

View Full Version : mysql_fetch_object(): error


Crowds
08-21-2006, 01:14 AM
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
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

GJay
08-21-2006, 07:28 AM
you attempted to put in error checking, but did it in the wrong place:

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

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

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

Crowds
08-21-2006, 10:54 AM
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 ! :rolleyes:
Sometimes I guess I should just walk away for a few hours.
Wood for the tree's and all that :D

Thanks again GJay !

Crowds