1

I want to have the print statements printed out on the browser. I tried but the code is not printing out. Please assist me with the code.

<?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);
print("Connection to the server opened"."<br>");

if ($db_found) {
print "Database 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);
}
?>
Kasturi R
  • 21
  • 6
  • Are you getting any errors? See http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php for how to enable error reporting in PHP. – Barmar Jul 07 '16 at 16:15
  • 1
    If you'd bothered actually checking for errors, and not using `@` (the php equivalent of stuffing your fingers in your ears and going "lalalalalala can't hear you"), perhaps you would find out why the code isn't working. Never EVER assume success with external operations, especially database operations. always assume failure, check for failure, and treat success as a pleasant surprise. – Marc B Jul 07 '16 at 16:15
  • A proper print is like this: print_r($variable); but you'll want to replace those "print"'s with echo – awl19 Jul 07 '16 at 16:15
  • @awl19 Why is `echo` better than `print`? – Barmar Jul 07 '16 at 16:16
  • @Barmar Correction on my part. I've actually hardly seen print used, but print will return 1 even if the variable doesn't exist, while echo will throw an error. – awl19 Jul 07 '16 at 16:18
  • @awl19 I just tried it, and `print $foo;` reported "Notice: undefined variable foo` just like `echo` would. See http://stackoverflow.com/questions/234241/how-are-echo-and-print-different-in-php – Barmar Jul 07 '16 at 16:20
  • @Barmar My mistake. – awl19 Jul 07 '16 at 16:20

0 Answers0