PHP MySQL contact us form with validation using Bootstrap

PHP MySQL contact us form with validation using Bootstrap

In this post we will give you information about PHP MySQL contact us form with validation using Bootstrap. Hear we will give you detail about PHP MySQL contact us form with validation using BootstrapAnd how to use it also give you demo for it if it is necessary.

Today, i am going to share with you how to create custom contact form in PHP and store in mysql database. You can simply create enquiry form or feedback form with validation using bootstrap design.

Contact US Or Feedback form is a very basic feature of every website because that way customer can contact to website administrator for enquiry or give feedback about the website. So if you are beginner of php language then it’s become more useful to you and also if you want to make quick contact us form in your core php project then you are a right place.

So, now you have to simply follow some few step and get then perfect contact form in your php project. In this example i used php, mysql and bootstrap for creating contact form. i will create “contactus” form with id, name, email, message and created_date fields.

So just simply follow bellow step and get your simple contact us form.

Step 1: Create contactus table

Here, we will create new new table “contactus” in database. You can use following SQL Query for create “contactus” table. So let’s create using bellow sql query:

contactus table:

CREATE TABLE 'contactus' (

'id' int(10) UNSIGNED NOT NULL,

'name' varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,

'email' varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,

'message' text COLLATE utf8mb4_unicode_ci NOT NULL,

'created_date' date DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

Step 2: DataBase Configuration File

In second step, we require to create database configuration file, here we will set database name, username and password. So let’s create “config.php” file on your root directory and put bellow code:

config.php

<?php


define (DB_USER, "root");

define (DB_PASSWORD, "root");

define (DB_DATABASE, "sole");

define (DB_HOST, "localhost");


$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);

?>

Also see:PHP AngularJS CRUD with Search and Pagination Example From Scratch

Step 3: Create index.php

Now, we create index.php file, in this file we will write code for create new form. So let’s create index.php file on your root directory and put bellow code.


index.php

<!DOCTYPE html>

<html>

<head>

<title>PHP MySQL contact us form with validation using Bootstrap</title>

<!-- Latest compiled and minified CSS -->

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

</head>

<body>


<div >

<h3>PHP MySQL contact us form with validation using Bootstrap</h3>

<form action="pro.php" method="POST">

<div >

<label>Name:</label>

<input type="text" name="name" required>

</div>

<div >

<label>Email:</label>

<input type="email" name="email" required>

</div>

<div >

<label>Message:</label>

<textarea name="message" required></textarea>

</div>

<div >

<button type="submit">Submit</button>

</div>

</form>

</div>


</body>

</html>

Step 4: Create pro.php

In last step we will create pro.php file, in this file we will get all post data and store it on database, so let’s create another file pro.php on your root path and put bellow code.

data.php

Also see:jQuery Ajax X-editable bootstrap plugin to update records in PHP Example

<?php


require('config.php');


extract($_POST);


$sql = "INSERT into contactus (name,email,message,created_date) VALUES('" . $name . "','" . $email . "','" . $message . "','" . date('Y-m-d') . "')";


$success = $mysqli->query($sql);


if (!$success) {

die("Couldn't enter data: ".$mysqli->error);

}


echo "Thank You For Contacting Us ";


$conn->close();


?>

Now we are ready to run our custom contact form in code php. So let’s run index.php file and see, is every thing right ?

I hope it can help you…

Hope this code and post will helped you for implement PHP MySQL contact us form with validation using Bootstrap. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

3  +  6  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US