If we want to insert our Form data in MySQL, first we have to create a Registartion Form
(If you want to awosome Form than use bootstarp), Therefore create database using XAMPP or any
other server.
Here we using 3 core file for insert data in MySQL( Database file is Saparate):
Registration Form
We use a registration form using Bootstrap.
Insert_Form.php
<html>
<head>
<title> Insert_Form_Value</title>
/* insert css using bootstrap */
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="js/bootstrap.min.js"> </script>
<link rel="stylesheet" href="fonts/font-awesome.min.css">
</head>
<body>
<div class="container">
<h2> Stacked form</h2>
<form action="process.php" method ="Post" >
<div class="form-group">
<label for="Name"> Name:</label>
<input type="text" class="form-control" placeholder="Enter Name" name="name">
</div>
<div class="form-group">
<label for="email"> Email:</label>
<input type="email" class="form-control" placeholder="Enter email" name="email">
</div>
<div class="form-group">
<label for="Phone"> Phone:</label>
<input type="text" class="form-control" placeholder="Enter Phone" name="phone">
</div>
<button type="submit" class="btn btn-primary btn-block" name="Submit"> Submit</button>
</form>
</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`
--