In this video tutorial, we will learn How to insert data into MySQL Database Table Using PHP. In previous blog tutorials we learn how to How to Make Header Section in Website Using HTML and CSS | E-CODEC
I'm happy to post here my insight and methods utilized in PHP and MySQL. As you all mindful that PHP and MySQL are the most broadly utilized open source for sites. the present great many sites and application are utilizing these free software's.
Actually I feel that this could be next level for front end developer by utilizing PHP and MySQL a HTML designer can make a site more unique. Allow us to talk about How to Insert Data into Database Using PHP MySQL, Its straight forward and exceptionally valuable for an essential site dynamic client dynamic enlistment.
Each innovative can execute its essential construction to their site. Presently Just follow these basic advances and you will find that your first dynamic functional PHP registration form with database connection entry on every form fill up.
So here is the code and my work. I hope you are gonna love this and share whit your friends too. So let's start learning a insert data into database using PHP MySQL from scratch. So let's start.
In this tutorial you will learn to insert records in a MySQL table using PHP coding, subscribe E-CODEC channel to watch more videos on website designing tutorials for beginners.
I hope you enjoyed this video tutorial. If you had any doubts, then please comment them below. And if you enjoyed this tutorial, then please hit the like button below and subscribe my channel. Thank you..
Inserting Data into Database Using PHP MySQL
In this tutorial you will also see How to create Database and Tale. First we need a server like (XAMPP, WAMP) one local server required for running PHP Script because PHP is a Server Site Scripting Language. I hope you all are installing local server, so let’s start creating Database and Database Table. Second thing you start the local server, I have using XAMPP server, you can use another one also.
Open any browser in computer and type in url 127.0.0.1/phpmyadmin and press enter you find a option Database click here and time Database and in my case database name is tutorials you can take any other name also. In side menu ypu can find your Database name ‘tutorials’ click on it. Now you see new option click on it and you see create table field where type table name in my case table name is insert_data . You can paste code in the SQL, Here code given below. For more details watch my video.
STEP 1: Create Database for inserting values
CREATE TABLE `data_insert` (
`id` int(11) NOT NULL,
`name` varchar(100) NOT NULL,
`email` varchar(150) NOT NULL,
`mobile` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
STEP 2: Create HTML Login Form (Front end code)
Create a new file index.php, Here is the code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert data in database using PHP MySQLi</title>
<style type="text/css">
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
body{
background: #5d6d7d;
width: 100%;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.container{
width: 500px;
background: #fff;
}
.container form{
width: 100%;
padding: 30px;
}
.container form input{
width: 100%;
padding: 15px 10px;
outline: none;
margin: 10px 0;
}
.btn{
cursor: pointer;
background: red;
border: none;
padding: 10px 30px;
color: #fff;
}
h1{
display: block;
text-align: center;
padding-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h1>Insert Data</h1>
<form method="post" action="">
<input type="text" name="name" placeholder="Enter your name" required>
<input type="email" name="email" placeholder="Enter your email address" required>
<input type="text" name="number" placeholder="Enter your mobile number" required>
<input type="submit" name="insert" value="Insert Data" class="btn"><br>
<?php echo $msg; ?>
</form>
</div>
</body>
</html>
STEP 3: For Database connectivity using MySQL
Make a connection.php file for stablished connection database use that default code as below
$conn=mysqli_connect('localhost','root','','tutorials') or die();
STEP 4: Finally make a login page with login.php extension
From get value of all fields shown in HTML page
<?php
//index.php
$conn=mysqli_connect('localhost','root','','tutorials') or die();
$msg="";
if (isset($_POST['insert'])) {
$name=$_POST['name'];
$email=$_POST['email'];
$number=$_POST['number'];
$query= "INSERT INTO `data_insert`(`name`, `email`, `mobile`) VALUES ('$name','$email','$number')";
$data=mysqli_query($conn,$query);
if ($data) {
$msg="Your data inserted successfully";
}else{
$msg="Try after some time !";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert data in database using PHP MySQLi</title>
<style type="text/css">
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
body{
background: #5d6d7d;
width: 100%;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.container{
width: 500px;
background: #fff;
}
.container form{
width: 100%;
padding: 30px;
}
.container form input{
width: 100%;
padding: 15px 10px;
outline: none;
margin: 10px 0;
}
.btn{
cursor: pointer;
background: red;
border: none;
padding: 10px 30px;
color: #fff;
}
h1{
display: block;
text-align: center;
padding-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h1>Insert Data</h1>
<form method="post" action="">
<input type="text" name="name" placeholder="Enter your name" required>
<input type="email" name="email" placeholder="Enter your email address" required>
<input type="text" name="number" placeholder="Enter your mobile number" required>
<input type="submit" name="insert" value="Insert Data" class="btn"><br>
<?php echo $msg; ?>
</form>
</div>
</body>
</html>
Here a Front end developer can keep in touch with some own code in PHP, Read the code and comprehend this essential design line by line you will think that its extremely simple.
Conclusion
By following bit by bit strategy gave over a fundamental login form can be made. So best of luck for your first PHP code.
You can also learn:- Basic Login Form in PHP with MySQL database connectivity | E-CODEC
0 Comments