I'm using this PHP code to learn databases and PHP, though I'm receiving the error message:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/index.php on line 20
At first, the SQL query turned out to contain I spelling error which I have recently fixed, and I've ran the SQL query directly in PHPMyAdmin - where it works as it should. I can't find any reasonable hints using the mysql_error()
line.
Here's the rest of the code:
<!DOCTYPE html>
<html>
<body>
<?php
$user_name = "root";
$password = "";
$database = "addressbook";
$server = "localhost";
$db_handle = new mysqli($server, $user_name, $password);
$db_found = $db_handle->select_db($database);
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>";
}
$db_handle->close();
} else {
print "Database NOT found";
$db_handle->close();
}
?>
</body>
</html>
Doing
if ($result) {
}
returns false
What am I doing wrong?