reading a record with php

Thomsika

New Member
Messages
1
Reaction score
0
Points
0
<?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'] . "<BR>";
print $db_field['First_Name'] . "<BR>";
print $db_field['Surname'] . "<BR>";
print $db_field['Address'] . "<BR>";

}
mysql_close($db_handle);
}
else {

print "Database NOT Found ";
mysql_close($db_handle);

}
?>


Can anyone help me??
When i am running this program, i am not getting output and i get a warning like below..
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\code\server connection.php on line 13

Pls help me to solve this issue
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
What it is telling you is that

$result = mysql_query($SQL);

Is returning FALSE , signifying an error. Either you do not have permission to query that table or that table does not exist.

To debug, add :

if (!$result) {
die('Invalid query: ' . mysql_error());
}

right after that line to see what the mysql error message is. Comment out the code once you find and fix the problem.
 
Top