php mysql contact form - Web Development and Online Earning Tutorials

Latest

Like Box

BANNER 728X90
BANNER 728X90

Tuesday, February 13, 2018

php mysql contact form

PHP MySQL Contact Form

php mysql contact form
php mysql contact form

Hi Guys Today We will learn how to Create PHP MySQL Contact Form.

What you need..

first create a database named: test
create table named: contact
table structure:
php mysql contact form
php mysql contact form

Now use The below SQL Commands to Create a table(contact)
Table structure for table `contact` --
CREATE TABLE IF NOT EXISTS `contact` (
  `id` int(11) NOT NULL,
  `name` varchar(20) NOT NULL,
  `email` varchar(50) NOT NULL,
  `content` varchar(200) NOT NULL,
  `title` varchar(100) NOT NULL
) ENGINE=MyISAM AUTO_INCREMENT=16 DEFAULT CHARSET=latin1;

1.create connect.php file.
2.create index.html file.
3.create contact.php file.
4.create style.css file.
1.Creating connect.php to connect database.
<?php
$host="localhost"; //Your Host Name
$username="root"; //Your MySQL UserName
$pass=""; //Your MySQL PassWord
$dbname="test"; //Your Database Name
//Connect to Server
mysql_connect("$host","$username","$pass");
//Select Database
mysql_select_db("$dbname");
?>

2.Createing index.html page
<html>
<head>
<title>PHP MySQL Contact Form</title>
<link rel="stylesheet" href="style.css" type="text/css"/>
</head>
<div id="contact">
<h2>PHP MySQL Simple Contact form</h2>
<form method="POST" action="contact.php">
<table>
    <tr>
	   <td><span>Name:</span></td>
	   <td><input type='text' name='name' placeholder="Your Name" required/></td>
	</tr>
	<tr>
	   <td><span>Email:</span></td>
	   <td><input type='text' name='email' placeholder="Your Email Address Here" required/></td>
	</tr>
	<tr>
	   <td><span>Problem Title:</span></td>
	   <td><input type='text' name='title' placeholder="Your Problem Title Here" required/></td>
	</tr>
	<tr>
	   <td><span>Content:</span></td>
	   <td><textarea name='content' rows='10' cols='40' placeholder="Your Problems Description Here" required></textarea></td>
	</tr>
	<tr>
	   <td></td>
	   <td><input type='submit' name='submit' value="Contact Now"/></td>
	</tr>
</table>
</form>
</div>
</html>

3.Creating contact.php page to process and save data in database
<
  include("connect.php");
  if(isset($_POST['submit'])){
	  $name=mysql_real_escape_string($_POST['name']);
	  $email=mysql_real_escape_string($_POST['email']);
	  $title=mysql_real_escape_string($_POST['title']);
	  $content=mysql_real_escape_string($_POST['content']);
	  
	  $sql="INSERT INTO contact(name,email,title,content)VALUES('$name','$email','$title','$content')";
	  $result=mysql_query($sql);
	  if($result){
	  	echo "Thank You for Contact us. we will Response Within 24 Hours";
	  }else{
	  	echo "Sorry We can not Process your Message";
	  }
  }
?>

4.Creating style.css page to design our index.html page
#contact{
	margin:auto;
	background:#ddd;
    border:1px solid #080808;
	width:500px;
}
span{
	font-size:15px;
	font-weight:bold;
}
input[type=text]{
	padding:10px;
	width:300px;
	border-radius:4px;
}
textarea{
	width:300px;
	border-radius:4px;
}
input[type=submit]{
	padding:6px;
	color:white;
	background:#080808;
	font-weight:bold;
	border-radius:5px;
}
That's all, this is how to create PHP MySQL Contact Form. You can customize this codes further as per your requirement. feel free to give your comment on this tutorial.

No comments:

Post a Comment

Thank You for Your Comment