If we want to View our Form data in MySQL, first we have to create a table.
(If you want to awosome Form than use bootstarp), Therefore we fatch all value form MySqli database using XAMPP or any
other server.
Here we using 2 core file for insert data in MySQL( Database file is Saparate):
View Registration Form Value
View_Form.php
<!DOCTYPE html>
<html>
<head>
<title> Insert_Form_Value</title>
/* View Form Value */
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous">
<link rel="stylesheet" href="fonts/font-awesome.min.css">
</head>
<body>
<div class="container">
<h2>
<a href="Insert_Form.php"> Stacked form </a>
<a href="view_form.php">View Details</a>
<a href="edit.php">Edit Form</a>
<a href="delete_form.php">Delete Form</a>
</h2>
<h2> View form</h2>
<table class="table table-striped">
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Email</th>
<th scope="col">Phone</th>
</tr>
<?php
include('db_conection.php');
$view_users_query = "SELECT * FROM registration ";
$run=mysqli_query($dbcon,$view_users_query); //here run the sql query.
$counter = 1;
while($DataRows=mysqli_fetch_array($run)) //while look to fetch the result and store in a array $row.
{
?>
<tr>
<th scope="row">
<?php echo $counter; ?>
</th>
<td>
<?php echo $DataRows["name"]; ?>
</td>
<td>
<?php echo $DataRows["email"]; ?>
</td>
<td>
<?php echo $DataRows["phone"]; ?>
</td>
</tr>
<?php $counter++; } ?>
</table>
</div>
</body>
</html>
O/P:-
db_conection.php
$dbcon=mysqli_connect("localhost", "root" , "");
mysqli_select_db($dbcon, "Crud");
?>
process.php
include("db_conection.php");
if(isset($_POST['Submit']))
{
/*
mysqli_real_escape_string():-used for Escape special characters in a string. Avoid hacking , Must bu used this function
*/
$Name = mysqli_real_escape_string($dbcon, $_POST["name"]);
$Email = mysqli_real_escape_string($dbcon, $_POST["email"]);
$Number = mysqli_real_escape_string($dbcon, $_POST["phone"]);
/*
Insert Query:- Here The line your Form value insert in Database.
*/
$insert_user="insert into registration(name, email, phone)
Values('$Name', '$Email', '$Number')";
if(mysqli_query($dbcon, $insert_user))
{
/*
Display Output:- Here The Particular Code show the Successfully Message.
*/
echo " <script> alert('data submitted successfully') </script>";
echo " <script> window.open('Insert_Form.php?msg=You are Successfully Registered !', '_self') </script>";
}
}
?>
Database
-- Database: `Crud`
--
-- ---------------------------------
--
-- Table structure for table `registration`
--
CREATE TABLE IF NOT EXISTS `registration` (
`id` int(5) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`email` varchar(100) NOT NULL,
`phone` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Dumping data for table `registration`
--