Help with MySQL query

So i’m studying PHP and MySQL with these tutorials on the internet. I’m trying to display records which I have created in my database via phpmyadmin using PHP code, but the code in the tutorial doesn’t work, I get a ‘mysql_fetch_assoc() expects parameter 1 to be resource, boolean given’ error when executing the following code:

[php]

<?PHP $user_name = "root"; $password = ""; $database = "addressbook"; $server = "127.0.0.1"; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); if ($db_found) { $SQL = "SELECT * FROM tb_address_book"; $result = mysql_query($SQL); while ( $db_field = mysql_fetch_assoc($result) ) { print $db_field['ID'] . "
"; print $db_field['First_Name'] . "
"; print $db_field['Surname'] . "
"; print $db_field['Address'] . "
"; } mysql_close($db_handle); } else { print "Database NOT Found "; mysql_close($db_handle); } ?>[/php]

Anyone know whats wrong with it?

Thanks :slight_smile:

Nevermind guys, the table name was wrong. It was supposed to be tbl_address_book not tb_address_book. Haha.

You’re reading a bad outdated tutorial.

Sponsor our Newsletter | Privacy Policy | Terms of Service