MySQL Forums
Forum List  »  PHP

PHP & MySQL Error: mysql_fetch_assoc
Posted by: Asharfi Vig
Date: July 26, 2009 04:55PM

Hello, friends!

I am trying to make a simple script that takes some information from the database and outputs it to user's webpage window. I am a newbie to PHP & MySQL, but this is not my first time writing something like this. I have created a similar script in the past that displayed information from the database to the user's webpage window. Now, the error I am having is below:

mysql_fetch_assoc supplied argument is not a valid mysql result resource

I have checked my code over 20 times already and I don't see any code errors or SQL query errors. This script's code is based on its first version. I tried many WAMP servers, such as UniServer, EasyPHP, WampServer2, etc. Please help me solve this problem.

I can also post my code here if you want. The only thing that I don't get is why my old script is working and this new one isn't? 95% of the code is same. The new application has some graphics and extra features, that's it. I am using a while loop to fetch stuff from my database. Below is my PHP code that is giving me the problem:

<?php

$query = mysql_query("SELECT * FROM `comments` WHERE username='$username'");
while ($result = mysql_fetch_assoc($query))
{
  echo $result["username"] . "says: " . $result["comment"];
}

?>

Options: ReplyQuote


Subject
Written By
Posted
PHP & MySQL Error: mysql_fetch_assoc
July 26, 2009 04:55PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.