1<form id="contactForm1" action="/your_url" method="post">
2 <!-- Form input fields here (do not forget your name attributes). -->
3</form>
4
5<script type="text/javascript">
6 var frm = $('#contactForm1');
7
8 frm.submit(function (e) {
9
10 e.preventDefault();
11
12 $.ajax({
13 type: frm.attr('method'),
14 url: frm.attr('action'),
15 data: frm.serialize(),
16 success: function (data) {
17 console.log('Submission was successful.');
18 console.log(data);
19 },
20 error: function (data) {
21 console.log('An error occurred.');
22 console.log(data);
23 },
24 });
25 });
26</script>
27
1// Database Structure
2CREATE TABLE `contacts` (
3 `id` int(11) NOT NULL AUTO_INCREMENT,
4 `name` text NOT NULL,
5 `email` text NOT NULL,
6 `reason` text NOT NULL,
7 `message` text NOT NULL,
8 PRIMARY KEY (`id`)
9) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
10
11<?php
12if(isset($_POST['submit_contact']))
13{
14 $name=$_POST['name'];
15 $email=$_POST['email'];
16 $reason=$_POST['reason'];
17 $message=$_POST['message'];
18
19 $host="localhost";
20 $username="root";
21 $password="";
22 $databasename="sample";
23 $connect=mysql_connect($host,$username,$password);
24 $db=mysql_select_db($databasename);
25
26 mysql_query("insert into contacts values('','$name','$email','$reason','$message')");
27 echo "submitted";
28 exit();
29}
30?>