<?php require_once("PasswordMstr.php"); ?>

<!DOCTYPE html PUBLIC

"-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Display Address Book</title>

<link rel="stylesheet" href="php_styles.css" type="text/css" />

</head>

<body>

<h3>Current Records in Address Book</h3>

<?php

// $DBConnect = @mysqli_connect("localhost", "root")                                                                                 // (Test)  Connect to MySQL                

$DBConnect = mysqli_connect("db1234.abcdefg.net", "db1234567890", "abcdefgh", "db1234567890")   // Connect to MySQL

                Or die("<p>Unable to connect to data base server.</p>"

                . "<p>Error code " . mysqli_connect_errno()

                . "; " . mysqli_connect_error()) . "</p>";

 

// $DBName = "AddressBook";                                                                                                                                                                  // (Test)                               

$DBName = "db240712012";                                                                                                      

mysqli_select_db($DBConnect, $DBName)                                                                                         // Select Data base

                Or die("<p>Unable to select the data base.</p>"

                                . "<p>Error code " . mysqli_errno($DBConnect)

                                . "; " . mysqli_error($DBConnect)) . "</p>";

 

$TableName = "persons";                                                                                                                                                            // Read the Table

$SQLstring = "SELECT * FROM $TableName ORDER BY name";

$QueryResult = @mysqli_query($DBConnect, $SQLstring)           

                Or die("<p>Unable to Read the table.</p>"

                                . "<p>Error code " . mysqli_errno($DBConnect)

                                . "; " . mysqli_error($DBConnect)) . "</p>";

 

if (mysqli_num_rows($QueryResult) == 0)                                                                                           //  Display data

                die("<p>There are no records. Click back.</p>");

echo "<table width='100%' border='1'>";

echo "<tr><th>ID</th><th>Name</th><th>E-Mail</th><th>Phone</th><th>Address</th><th>Update</th><th>Delete</th></tr>";

$Row = mysqli_fetch_assoc($QueryResult);

do

{

                echo "<tr><td>{$Row['personID']}</td>";

                echo "<td>{$Row['name']}</td>";

                echo "<td>{$Row['email']}</td>";

                echo "<td>{$Row['phone']}</td>";

                echo "<td>{$Row['address']}</td>";

    ?>

                    <td>

        <form method = "get" action="UpdateDisplay.php">

        <input type="submit" value="Update" />

        <input type="hidden" name="UpPersonID" value="<?= $Row['personID'] ?>" />

                                <input type="hidden" name="UpName" value="<?= $Row['name'] ?>" />

                    <input type="hidden" name="UpEmail" value="<?= $Row['email'] ?>" />

        <input type="hidden" name="UpPhone" value="<?= $Row['phone'] ?>" />

        <input type="hidden" name="UpAddress" value="<?= $Row['address'] ?>" />                         

        </form>

                               

        </td>

        <td>

        <form method = "get" action="DeleteARecord.php">

        <input type="submit" value="Delete" />

        <input type="hidden" name="DelPersonID" value="<?= $Row['personID'] ?>" />

        </form>

        </td></tr>

    <?php              

                $Row = mysqli_fetch_assoc($QueryResult);

} while($Row);

 

mysqli_free_result($QueryResult);                                                                                                         // Close Data base

mysqli_close($DBConnect);       

echo "<p><a href='indexMstr.php'>Return to Menu Page</a></p>";

?>

 

</body>

</html>