Hello @Sign,
It is simple to create contact form to send email or any other information and storing in mysql database.
Using INSERT INTO statement you can insert new data into a database table.
See the example below:
Output:
![](https://www.edureka.co/community/?qa=blob&qa_blobid=7557490628519146793)
![](denied:data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWAAAACtCAYAAACOYKWSAAAYaElEQVR4Ae2dzWscR/rH939qCOiwIPiBIAed1vwghoWYHOI1WBDwKBCRw5oFW6uDMETsYXHAiM1GGMz4YBSwJmAiQZAPYmwC8uKMQTAYwYBgFh8GDM9Sb11PdddMt2ZaVT09X8EwPf1SL5+u+nT1093qPxD+QAAEQAAEohD4Q5RckSkIgAAIgABBwGgEIAACIBCJAAQcCTyyBQEQAAEIGG0ABEAABCIRgIAjgUe2IAACIAABow2AAAiAQCQCEHAk8MgWBEAABCBgtAEQAAEQiEQAAo4EHtmCAAiAAASMNgACIAACkQhAwJHAI1sQAAEQqFTAo4shDcXnAwM70vMuhjT6yOZjEgRAAAQWnMBUAh71u9R5tk/HZ0OLb3BMm6sJJUlCN74/JbVkRL3HN+W8ZOUudfp29ctPibTWbFrnl08BW4AACIBAnQgoAX8cUOfbJSW3RElUiDT3udOm/n971L6j1/1il06Ng5su4MswGtVpF6MsIAACdSUwm4A/f1i5gPvP79JyskQbP/XJ9VjkETAEXNc2jHKBwNwSyAv4s23aPzml0zf5T+9sKKU4fHdM+0/adPjWDH+JqIoR8McBHd5boaTuAi7BaG5bBAoOAiAQjEBewF/u0im/iOYpyrDfk4I2QparVCDg0VmH7uo48s3vD9ODQO9sQKOPnhHwaED9t/pA8bZHA3Y88BSbiEY0POvR6ckxHb86pd65O8b2b6Pn8hFwCUZOWrqc3ZfH1H3To/7FmHw/DKj39pR67/o0FBcsP45o8O6UukeHdPxbj/qifuk6gomo0lAy6L7s0unbPg0ySct9Jep7ckrO/nIKiB8gAAIxCFxewFxEIiZsOvwsAv44pO6/WrTiizuLeVJ4TMCf3KDNBxt0Pbf+Ndr4sUsDz90Wwzf7tPl5Pq597a971M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v7937coEcJLP7foh/9c5t7hwAL+5T4lyX06uqScIeCipoflIAACQQV8tCnEe3mZ8ftrLy4qFnCRWCFg9BIQAIErIhBQwFWJs6p0So66IeAranpIFgRAIKCAf6cf/lI0AtbrbB6x+K6aZ2O+SsD3fzHp6XBGuo2af/8XtZ4IdbjTRrx2uQyHpNur5flQic6nZPwZIQh0LhAAgSICAQUsxMal54v9lhewkGYqZX0h7f4vIg8jZpW+CnsICV+QnM6IVoQ3xs2XoQ+MgIvaEJaDAAhMSSCwgH2jTx4TLi/gVL46hmsl6qZh548XLV/HjTdf0AUEPGXTwmYgAAJFBCIJOCPidFTqylPJUM2zwlWjaPtbpSUlKm8lc9PgcuXTXLTj5mMEXNR8sBwEQGAWApEFrEel6T24rjwvLWApcjcNLlc+DQHP0mywLQiAQBUE4gpYx275aFZKMitkHu/13YYmwwQmplyxgJ34shm5F3/jIlwVzRNpgECzCYQTsHniLH0AQ91VoC6ccaHxC3XqQpuQspW0FqyTzvg4Mh/18mkV27V3NtgHQ3haqlzZOyJsWXi53WkIuNkdB7UDgSoIhBNw0QMPDVsOAVfRPJEGCDSbAAR8ReKHgJvdcVA7EKiCAAQMAVfRjpAGCIDAFAQgYAh4imaDTUAABKogAAFDwFW0I6QBAiAwBQEIGAKeotlgExAAgSoIQMAQcBXtCGmAAAhMQaAyAe/s7FCn02H/xcy9L5Y/edb0acFB8MAfCIAACEwiUJmA379/L6Ujbr9a9I+Qr+CBPxAAARCYRKAyAU/KBMtAAARAAATyBCDgPBPMAQEQAIEgBCDgIJiRCQiAAAjkCUDAeSaYAwIgAAJBCEDAQTAjExAAARDIE4CA80wwBwRAAASCEPgf9ZExPYlPdAgAAAAASUVORK5CYII=)
Step 1: Connection with Database
This is dbConn.php file which is used to connect the database.
This dbConn.php file will use everywhere, where you want to perform a task with the database.
Here it is connected with the local database and check database connected or not.
dbConn.php
<?php
$db = mysqli_connect("localhost","root","","testDB");
if(!$db)
{
die("Connection failed: " . mysqli_connect_error());
}
?>
Step 2: Creating HTML form and inserting data
Here's a simple HTML form which is index.php file. It has two text input and a submit button.
The INSERT INTO statement is used to add new data into the database. This insert query will execute passing through to the PHP mysqli_query() function to insert new data.
And also created a simple HTML form which has two input text and a submit button which is used to take data from users.
In the index.php file the dbConn.php file includes for connecting with the database and insert new data. The form has two field fullname and age which are get data from users and store into the database.
In this example the PHP code and the HTML form coded in the single page. The PHP script embedded with the HTML page.
index.php
<!DOCTYPE html>
<html>
<head>
<title>Add Records in Database</title>
</head>
<body>
<?php
include "dbConn.php"; // Using database connection file here
if(isset($_POST['submit']))
{
$fullname = $_POST['fullname'];
$age = $_POST['age'];
$insert = mysqli_query($db,"INSERT INTO `tblemp`(`fullname`, `age`) VALUES ('$fullname','$age')");
if(!$insert)
{
echo mysqli_error();
}
else
{
echo "Records added successfully.";
}
}
mysqli_close($db); // Close connection
?>
<h3>Fill the Form</h3>
<form method="POST">
Full Name : <input type="text" name="fullname" placeholder="Enter Full Name" Required>
<br/>
Age : <input type="text" name="age" placeholder="Enter Age" Required>
<br/>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
Write PHP code as a separate file
Step 1: Creating HTML Form
First of all creating HTML form which is index.php file. This form has two text boxes and a submit button for inserting data.
This form also has an action attribute which contains insert.php. This will perform when clicking on submit button.
index.php
<!DOCTYPE html>
<html>
<head>
<title>Add Records in Database</title>
</head>
<body>
<form action="insert.php" method="POST">
Full Name : <input type="text" name="fullname" placeholder="Enter Full Name" Required>
<br/>
Age : <input type="text" name="age" placeholder="Enter Age" Required>
<br/>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
Step 2: Connection with Database
This is dbConn.php file which connects the database.
dbConn.php
<?php
$db = mysqli_connect("localhost","root","","testDB");
if(!$db)
{
die("Connection failed: " . mysqli_connect_error());
}
?>
Step 3: Write PHP code for insert data
This is insert.php file. Here is written PHP code for inserting data when clicking on submit button.
insert.php
<?php
include "dbConn.php"; // Using database connection file here
if(isset($_POST['submit']))
{
$fullname = $_POST['fullname'];
$age = $_POST['age'];
$insert = mysqli_query($db,"INSERT INTO `tblemp`(`fullname`, `age`) VALUES ('$fullname','$age')");
if(!$insert)
{
echo mysqli_error();
}
else
{
echo "Records added successfully.";
}
}
mysqli_close($db); // Close connection
?>
Hope it helps!!
Thank you!