Lab #5

4. Write a program to read input data, from table and display all these information in table format on output screen in PHP

index.php

<?php

$db = mysqli_connect("localhost", "root", "", "testDB");

if (!$db) {
die("Connection failed: " . mysqli_connect_error());
}

?>

<!DOCTYPE html>
<html>

<head>
<title>Display all records from Database</title>
</head>

<body>

<h2>Employee Details</h2>

<table border="2">
<tr>
<td>Sr.No.</td>
<td>Full Name</td>
<td>Age</td>
</tr>

<?php

include "dbConn.php"; // Using database connection file here

$records = mysqli_query($db, "select * from tblemp"); // fetch data from database

while ($data = mysqli_fetch_array($records)) {
?>
<tr>
<td><?php echo $data['id']; ?></td>
<td><?php echo $data['fullname']; ?></td>
<td><?php echo $data['age']; ?></td>
</tr>
<?php
}
?>
</table>

<?php mysqli_close($db); // Close connection
?>

</body>

</html>

Output

Happy Coding :)