how to disply data in php?
Guide:
After a database and a table have been created,we can start insert records in it.
after all you need to insert record in data base using the form of html and php.
for insert record you need some html code ane insert query.
you need two pages.
table Query:
CREATE TABLE `register` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(30) NOT NULL,
`email` varchar(30) NOT NULL,
`password` varchar(30) NOT NULL,
`mobileno` bigint(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4
how to insert record ?
index.php page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form method="post">
<table>
<tr>
<td>Name</td>
<td><input type="text" name="txtname" value="<?php echo @$row[1]; ?>"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="email" name="txtemail" value="<?php echo @$row[2]; ?>"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="pass" name="txtpass" value="<?php echo @$row[3]; ?>"></td>
</tr>
<tr>
<td>Mobile No</td>
<td><input type="text" name="txtmobile" value="<?php echo @$row[4]; ?>"></td>
</tr>
<tr>
<td><input type="submit" name="insert" value="insert"></td>
<td> <a href="showdata.php">show data</a></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if (isset($_POST["insert"])) {
include("config.php");
$name = $_POST["txtname"];
$email = $_POST["txtemail"];
$pwd = $_POST["txtpass"];
$mobile = $_POST["txtmobile"];
$sql = "INSERT INTO register VALUES('', '$name','$email','$pwd','$mobile')";
$result = mysqli_query($conn, $sql);
if ($result) {
header("location:showdata.php");
}
}
?>
how to display data in our page?
The second operation is used to display or read the data that is already available in the database.
showdata.php page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="" method="post">
<table>
<tr>
<td><a href="index.php">add</a>
</td>
</tr>
</table>
<table border="2px">
<tr>
<td>id</td>
<td>name</td>
<td>email</td>
<td>password</td>
<td>mobileno</td>
<td>edit</td>
<td>delete</td>
</tr>
<?php
include("config.php");
$sql = "SELECT * FROM register";
$ins = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_row($ins)) {
?>
<tr>
<td><?php echo $row[0]; ?> </td>
<td><?php echo $row[1]; ?> </td>
<td><?php echo $row[2]; ?> </td>
<td><?php echo $row[3]; ?> </td>
<td><?php echo $row[4]; ?> </td>
</tr>
<?php
}
?>
</table>
<table>
<tr>
<td><a href="index.php">add</a></td>
</tr>
</table>
</form>
</body>
</html>
config.php page
<?php
$conn = mysqli_connect("localhost", "root", "", "viral");
?>
No comments:
Post a Comment
If You have any doubt, or want to know about something, please let me know