php mysql contact form - Web Development and Web Design Codes

Latest

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. easiest and less code 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 AUTO_INCREMENT,
  `name` varchar(20) NOT NULL,
  `email` varchar(50) NOT NULL,
  `content` varchar(200) NOT NULL,
  `title` varchar(100) NOT NULL,
  PRIMARY KEY(id)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

File Structure:

1. index.html file.
2. contact.php file.
3. style.css file.
1. 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>

2. contact.php page to process and save information to database
<?php
  $conn=new mysqli('localhost','root','','test');
  if(isset($_POST['submit'])){
   $name=$_POST['name'];
   $email=$_POST['email'];
   $title=$_POST['title'];
   $content=$_POST['content'];
    
   $result=mysqli_query($conn,"INSERT INTO contact(name,email,title,content)VALUES('$name','$email','$title','$content')");
   if($result){
    echo "Thank You for Contact us. we will Response Within 24 Hours";
   }else{
    echo "Sorry We can not Process your Message";
   }
  }
?>

3.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