I am a beginner learning PHP and MySQL and have gotten to chapter 5 of Head First PHP & MySQL and am attempting a self made project in which I created a database and a index.php
page where I can see the results printed out. When I go to my index.php
page I see the HTML title but the PHP code is not printing out my submissions. I have to assume my code syntax is correct or I would end up with a blank page. Can someone please tell me what I have coded wrong to wind up with no output?
<?php
$dbc = mysqli_connect(localhost, root, root, itmyfamily);
$query = "SELECT * FROM itsmyfamily ORDER BY last_name ASC, first_name DESC, date ASC";
$data = mysqli_query($dbc, $query);
$i = 0;
while ($row = mysqli_fetch_array($data))
{
if ($i == 0)
{
echo '<strong>First Name:</strong> ' . $row['first_name'] . ' <br />';
echo '<strong>Last Name:</strong> ' . $row['last_name'] . ' <br />';
echo '<strong>Spouse Name:</strong> ' . $row['spouse_name'] . ' <br />';
echo '<strong>Email:</strong> ' . $row['email'] . ' <br />';
}
else
{
echo 'There is no info in the database';
}
$i++;
}
mysqli_close($dbc);