I am trying to get some data from MySQL and echo it using PHP. Following is the code which I used. Please check the code and tell me what's wrong in it.
<?php
// Get a connection for the database
require_once('mysqli_connect.php');
// Create a query for the database
$query = "SELECT first_name, last_name, email, street, city, state, zip, phone, birth_date FROM testable";
// Get a response from the database by sending the connection and the query
$response = @mysqli_query($dbc, $query);
// If the query executed properly proceed
if($response){
echo '<table align="left"
cellspacing="5" cellpadding="8">
<tr><td align="left"><b>First Name</b></td>
<td align="left"><b>Last Name</b></td>
<td align="left"><b>Email</b></td>
<td align="left"><b>Street</b></td>
<td align="left"><b>City</b></td>
<td align="left"><b>State</b></td>
<td align="left"><b>Zip</b></td>
<td align="left"><b>Phone</b></td>
<td align="left"><b>Birth Day</b></td></tr>';
// mysqli_fetch_array will return a row of data from the query until no further data is available
while($row = mysqli_fetch_array($response)){
echo '<tr><td align="left">' .
$row['first_name'] . '</td><td align="left">' .
$row['last_name'] . '</td><td align="left">' .
$row['email'] . '</td><td align="left">' .
$row['street'] . '</td><td align="left">' .
$row['city'] . '</td><td align="left">' .
$row['state'] . '</td><td align="left">' .
$row['zip'] . '</td><td align="left">' .
$row['phone'] . '</td><td align="left">' .
$row['birth_date'] . '</td><td align="left">';
echo '</tr>';
}
echo '</table>';
} else {
echo "Couldn't issue database query<br />";
echo mysqli_error($dbc);
}
// Close connection to the database
mysqli_close($dbc);
?>
The output I am getting for this code is :
First Name Last Name Email Street City State Zip Phone Birth Day'; // mysqli_fetch_array will return a row of data from the query // until no further data is available while($row = mysqli_fetch_array($response)){ echo '' . $row['first_name'] . '' . $row['last_name'] . '' . $row['email'] . '' . $row['street'] . '' . $row['city'] . '' . $row['state'] . '' . $row['zip'] . '' . $row['phone'] . '' . $row['birth_date'] . ''; echo ''; } echo ''; } else { echo "Couldn't issue database query "; echo mysqli_error($dbc); } // Close connection to the database mysqli_close($dbc); ?>