<?php
define('DB_SERVER','localhost');
define('DB_USER','root');
define('DB_PASS' ,'');
define('DB_NAME', 'insertdb');
$con = mysqli_connect(DB_SERVER,DB_USER,DB_PASS,DB_NAME);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
index.php
<?php
include_once("config.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title> How to Fetch Data from MySql Database Using PHP</title>
<meta name="generator" content="Bootply" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<!--Bootstrap -->
<link rel="stylesheet" href="css/bootstrap.css" type="text/css">
<link rel="stylesheet" href="css/bootstrap.min.css" type="text/css">
</head>
<body>
<div class="container">
<div class="col-sm-8">
<div class="row">
<div class="col-xs-12">
<h3>How to fetch data into MySql dsing PHP </h3>
<hr >
<table width="100%" class="table table-bordered">
<tr>
<th>No.</th>
<th>Name</th>
<th>Email</th>
<th>Contact no.</th>
<th>Gender</th>
<th>Education</th>
<th>Address</th>
</tr>
<?php
$query=mysqli_query($con,"select * from data");
$cnt=1;
while($row=mysqli_fetch_array($query))
{
?>
<tr>
<td><?php echo $cnt;?></td>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['email'];?></td>
<td><?php echo $row['contactno'];?></td>
<td><?php echo $row['gender'];?></td>
<td><?php echo $row['education'];?></td>
<td><?php echo $row['address'];?></td>
</tr>
<?php
$cnt=$cnt+1;
} ?>
</table>
</div>
</div>
<hr>
</div>
</div>
<!-- Loading Scripts -->
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
Download