0

my script returns this error:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\wamp\www\php_test\user_inter.php on line 17

<?php
$db = mysql_connect("localhost");

mysql_select_db("room_p7", $db);

$query = "select * from members";
$result = mysql_query($query);

while($record=mysql_fetch_assoc($result)){

        while(list($fieldname, $fieldvalue) = each($record)){

            echo $fieldname.": <br>".$fieldvalue.":<br><br>";
            }

    echo "<br><br>";

    }
?>

Edited by deceptikon: Changed from code snippet to discussion thread

5
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by mohamedasif18
0

Add or die(mysql_error()); both to line 2 and 4 (and also 7 if you want to check the query). Probably you need to set username, password in mysql_connect(), because if there is no database connection, mysql_query() returns false and you get that error.

0

Here is the conection string,
My Username - root,
My PW - ;

<?php
$con = mysql_connect("localhost", "root", "") or die("Oops ! Server Not Connected");
$db = mysql_select_db("Your_DB") or die("Oops ! DB Not Connected");
?>

This question has already been answered. 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.