I am trying to get data from the database into an HTML page using HTML MySQL and PHP.
I created a php file with the code and a html where by pressing a button I call that function and show the information in the table (code below).
PHP:
<?php
include 'connection.php';
$sql = "SELECT cName, cEmail, cPhone, cOtherPhone, cAddress, cNeighborhood FROM Client WHERE cEmail='[email protected]'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "Name: " . $row["cName"]. "<br>";
echo "Email: " . $row["cEmail"]. "<br>";
echo "Phone number: " . $row["cPhone"]. "<br>";
echo "Other Phone number: " . $row["cOtherPhone"]. "<br>";
echo "Address: " . $row["cAddress"]. "<br>";
echo "Neighborhood: " . $row["cNeighborhood"]. "<br>";
}
} else {
echo "0 results";
}
?>
HTML
<HTML>
<HEAD>
<TITLE>
A Small Hello
</TITLE>
</HEAD>
<BODY>
<div>
<form id="myform" action="/My-code/getMyAccount.php" method="post">
<div class="button">
<button type="submit" name="submit">Update</button>
</div>
</form>
</BODY>
</HTML>
So far all is ok. Now I want to display the content without pressing any button. What I am doing is adding that php code in the html:
<HTML>
<HEAD>
<TITLE>
A Small Hello
</TITLE>
</HEAD>
<BODY>
<?php
include 'connection.php';
$sql = "SELECT cName, cEmail, cPhone, cOtherPhone, cAddress, cNeighborhood FROM Client WHERE cEmail='[email protected]'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "Name: " . $row["cName"]. "<br>";
echo "Email: " . $row["cEmail"]. "<br>";
echo "Phone number: " . $row["cPhone"]. "<br>";
echo "Other Phone number: " . $row["cOtherPhone"]. "<br>";
echo "Address: " . $row["cAddress"]. "<br>";
echo "Neighborhood: " . $row["cNeighborhood"]. "<br>";
}
} else {
echo "0 results";
}
?>
</BODY>
</HTML>
I am not getting any error, also in the console it writes 200 ok. But no data is display. How can I resolve this?