09 PHP application to add new Rows in a Table Program PHP- record
Note:- Three programs
01- index page,
02-connecting database,
03-adding row in a table.
save--index.php
program:-01
<!DOCTYPE html>
<html>
<head>
<title>Basic MySQLi Commands</title>
</head>
<body>
<div>
<form method="POST" action="add.php">
<label>UserId: </label><input type="text" name="userid"><br>
<label>Firstname:</label><input type="text" name="firstname"><br>
<label>Lastname:</label><input type="text" name="lastname"><br>
<label>E_Mail: </label><input type="text" name="E_mail"><br>
<input type="submit" name="add">
</form>
</div>
<br>
<div>
<table border="1">
<thead>
<th>UserId </th>
<th>Firstname</th>
<th>Lastname</th>
<th>E-Mail </th>
</thead>
<tbody>
<?php
include('conn.php');
$query=mysqli_query($conn,"select * from `user`");
while($row=mysqli_fetch_array($query)){
?>
<tr>
<td><?php echo $row['userid']; ?></td>
<td><?php echo $row['firstname']; ?></td>
<td><?php echo $row['lastname']; ?></td>
<td><?php echo $row['E_mail']; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</body>
</html>
save--conn.php
program:-02
<?php
$conn = mysqli_connect("localhost","root","","ibm_database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
save--add.php
program:-03
<?php
include('conn.php');
$userid=$_POST['userid'];
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$E_mail=$_POST['E_mail'];
mysqli_query($conn,"insert into `user` (userid,firstname,lastname,E_mail) values ('$userid','$firstname','$lastname','$E_mail')");
header('location:index.php');
?>
Note:- run to program in local server index.php
Output:-01
Output:-02
Output:-03
add total 5 persons details and submit
Comments
Post a Comment