Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Trouble printing table data with foreach loop

$
0
0

I'm struggling to print table data.  I have a simple address book in mysql and want to loop through each item and print.  I've read everything I can get my hands on and nothing is showing.  Any thoughts are greatly appreciated! Thanks for your time!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML  1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;  charset=utf-8"/>
<title>Creating Directory</title>
</head>
<body>
    
    <?php
    
    //Label variables
    $dbhost = "localhost";
    $dbuser = "xxxxxx";
    $dbpword = "xxxxxx";
    $dbname = "xxxxxx";
    $dbtable = "Address_Book";
    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $address = $_POST['address'];
    $phone = $_POST['phone'];
    $email = $_POST['email'];
    $bday = $_POST['bday'];

    //Initiate connection
    $con=mysqli_connect($dbhost, $dbuser, $dbpword, $dbname);

    // Check connection
    if (mysqli_connect_errno($con))
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    
    $result = mysqli_query( "SELECT * FROM $dbtable")  
    or die("SELECT Error: ".mysqli_error());
    
    while($data = mysqli_fetch_array($result, MYSQL_ASSOC)){
    foreach($data as $key => $value){
    echo $key;
    echo $value;
    } 
    }
    mysqli_close($con);
    
    ?>

    
    
   
</body>
</html>

Viewing all articles
Browse latest Browse all 13200

Trending Articles