0

Hi I am trying to teach myself some php and get this error (below) when I query a sql database this is just a tutorial and will never go live.

I have hilighted the area in bold where the unseen error is.

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /var/www/dbconnect1.php on line 14

<?php

        $dbhost = "localhost";
        $dbuser = "root";
        $dbpassword= "password";
        $dbdatabase = "productsdb";

        $db = mysql_connect($dbhost, $dbuser, $dbpassword);
        mysql_select_db($database, $db);

                $sql = "SELECT * FROM products";
                $result = mysql_query($sql);

                [B]while ($row = mysql_fetch_assoc($result)) {
                        echo $row['product'];[/B]
                        }

?>

please go easy on me as am a novice...

Edited by diafol: fixed formatting

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by emarkus
1

I would use mysql_fetch_array instead of mysql_fetch_assoc.

But your problem lies here:

mysql_select_db ($[B]db[/B]database, $db);
Votes + Comments
0

thanks so simple but just could not see it, its been driving me crazy.......

cant believe i could see that.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.