how to connect database with html & php full source code

DATABASE
"
....................... save this register.php.........................


<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<table>
<form method="get" action="register_insert.php">
<tr><td>Employee Name:</td><td>
<input type="text" name="emp_name">
</td></tr>
<tr><td>Employee Number</td><td>
<input type="number" name="emp_no">
</td></tr>
<tr><td>Employee Department:</td><td>
<input type="text" name="emp_dept">
</td></tr>
<tr><td>Employee Salary</td><td>
<input type="number" name="emp_salary">
</td></tr>
<tr><td>Employee Phone</td><td>
<input type="number" name="emp_ph">
</td></tr>
<tr><td>Employee Address</td><td>
<input type="text" name="emp_add">
</td></tr>
<tr><td>
<input type="submit" name="submit">
</td></tr>
</form>
</table>

</body>



................................save this view.php..................................

<?php
include("connect.php");
?>
<!DOCTYPE html>
<html>
<head>
<title>view</title>
</head>
<body>
<table align="center" border="1">
<thead>
<tr>
<th>SL NO.</th>
<th>NAME</th>
<th>EMP_NO</th>
<th>DEPARTMENT</th>
<th>SALARY</th>
<th>PHONE</th>
<th>ADDRESS</th>
<th>STATUS</th>
</tr>
</thead>
<?php
$sql="SELECT * FROM employee_info";
$qry=mysqli_query($con,$sql);
$sl=1;
while($row=mysqli_fetch_array($qry)) {


?>
<tbody>
<tr>
<td><?php echo $sl; ?></td>
<td><?php echo $row['emp_name']; ?></td>
<td><?php echo $row['emp_no']; ?></td>
<td><?php echo $row['emp_dept']; ?></td>
<td><?php echo $row['emp_salary']; ?></td>
<td><?php echo $row['emp_phone']; ?></td>
<td><?php echo $row['emp_address']; ?></td>
<td><?php echo $row['status']; ?></td>
</tr>
<?php $sl++;
} ?>
</tbody>
</table>
</body>
</html>


.................................save this - register_insert.php..........................................

<?php
if(isset($_GET['submit'])){
$name=$_GET['emp_name'];
$no=$_GET['emp_no'];
$dept=$_GET['emp_dept'];
$sal=$_GET['emp_salary'];
$ph=$_GET['emp_ph'];
$add=$_GET['emp_add'];

$host="localhost";
$user="root";
$pass="";
$db="sip";

$con=mysqli_connect($host,$user,$pass,$db) or die(mysqli_error($con));

$sql="INSERT INTO employee_info VALUES('0','$name','$no','$dept','$sal','$ph','$add','0')";

$qry=mysqli_query($con,$sql);

if($qry){
header("Location:view.php");
}else{
echo "data not inserted".mysqli_error($con);
}




}
?>

.................................save this connect.php....................................

<?php
$host="localhost";
$user="root";
$pass="";
$db="sip";

$con=mysqli_connect($host,$user,$pass,$db) or die(mysqli_error($con));

?>
"

Comments

  1. great pice of work.



    hope more from you

    ReplyDelete

Post a Comment