1<?php
2// database connection code
3// $con = mysqli_connect('localhost', 'database_user', 'database_password','database');
4
5$con = mysqli_connect('localhost', 'root', '','db_connect');
6
7// get the post records
8$txtName = $_POST['txtName'];
9$txtEmail = $_POST['txtEmail'];
10$txtPhone = $_POST['txtPhone'];
11$txtMessage = $_POST['txtMessage'];
12
13// database insert SQL code
14$sql = "INSERT INTO `tbl_contact` (`Id`, `fldName`, `fldEmail`, `fldPhone`, `fldMessage`) VALUES ('0', '$txtName', '$txtEmail', '$txtPhone', '$txtMessage')";
15
16// insert in database
17$rs = mysqli_query($con, $sql);
18
19if($rs)
20{
21 echo "Contact Records Inserted";
22}
23
24?>
1$con = mysqli_connect('localhost', 'root', '',’db_connect’);
2The “db_connect” is our database name that we created before.
3After connection database you need to take post variable from the form. See the below code
4$txtName = $_POST['txtName'];
5$txtEmail = $_POST['txtEmail'];
6$txtPhone = $_POST['txtPhone'];
7$txtMessage = $_POST['txtMessage'];
1<!DOCTYPE html>
2<html xmlns="http://www.w3.org/1999/xhtml">
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5<title>Contact Form - PHP/MySQL Demo Code</title>
6</head>
7
8<body>
9<fieldset>
10<legend>Contact Form</legend>
11<form name="frmContact" method="post" action="contact.php">
12<p>
13<label for="Name">Name </label>
14<input type="text" name="txtName" id="txtName">
15</p>
16<p>
17<label for="email">Email</label>
18<input type="text" name="txtEmail" id="txtEmail">
19</p>
20<p>
21<label for="phone">Phone</label>
22<input type="text" name="txtPhone" id="txtPhone">
23</p>
24<p>
25<label for="message">Message</label>
26<textarea name="txtMessage" id="txtMessage"></textarea>
27</p>
28<p> </p>
29<p>
30<input type="submit" name="Submit" id="Submit" value="Submit">
31</p>
32</form>
33</fieldset>
34</body>
35</html>
36