mysql_fetch_assoc(): supplied argument is not a valid MySQ

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
huntsvillepr
Forum Newbie
Posts: 7
Joined: Wed Nov 18, 2009 2:21 am

mysql_fetch_assoc(): supplied argument is not a valid MySQ

Post by huntsvillepr »

Please help. I am getting error message mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

I have tested my connection and it works
I am getting result from echo $result

What I'm i doing wrong?

<?php
$con = mysql_connect("local","password","user");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

if (!mysql_select_db("dbname", $con)) {
exit('<p>Unable to connect');
}

$result = mysql_query ("SELECT id, title, description FROM dir_categories ");

if (!$result) {
echo 'no, no ';
}

echo $result;

$answer = mysql_query ($result);

while ($row = mysql_fetch_assoc ($answer)) {

echo '<title>'.htmlentities($row['title']).'</title>';
echo '<description>'.htmlentities($row['description']).'</description>';

}

mysql_close($con);
?>
User avatar
BlaineSch
Forum Commoner
Posts: 28
Joined: Sun Jun 07, 2009 4:28 pm
Location: Trapped in my own little world.

Re: mysql_fetch_assoc(): supplied argument is not a valid MySQ

Post by BlaineSch »

First of all use code tags!

Second, there are many things that could be wrong. If you table is empty you could be getting this.

Also try and use MySQLi because mysql is being depreciated.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: mysql_fetch_assoc(): supplied argument is not a valid MySQ

Post by requinix »

Also,

Code: Select all

$result = mysql_query ("SELECT id, title, description FROM dir_categories ");
$answer = mysql_query ($result);
You run a query through mysql_query, then take the resource you get back and run it through mysql_query... $answer is false because $result is not a valid SQL query.
huntsvillepr
Forum Newbie
Posts: 7
Joined: Wed Nov 18, 2009 2:21 am

Re: mysql_fetch_assoc(): supplied argument is not a valid MySQ

Post by huntsvillepr »

thanks. the way i did the query was the problem
Post Reply