Indian Pincode search with all courier services availability using php and MySql.

In this tutorials I am going to explore you a very useful script for your ecommerce websites. Every online shopping projects and other postal based projects needs this script for their websites . We can see every courier companies provide the location finder using pincode for customers. Customers can also check their pincode for delivery service availability on their location.

We can see also all top eCommerce websites provide this facility for customers to check their pincode before buying products. So that customers can check product is deliverable or not on their location. So here I am going to show you how to create a location finder script by pincode using php, jquery and mysql.

Here is the output of the page:

indian-pincode-search-using-php

Implementation of Database and Tables:

First you need to create a Database indianpincode. After creating database (indianpincode), you will have to create a Table Pincode. Here Table Pincode has four columns ( pincode, courier_company, city_name and state_name). These fields are use to store the Pincode, State Name , City Name and Courier Company Name .

Pincode.sql: This table contains thousands of rows so i can not show source code of this table. You can download it from this site or you can get it online in Excel Form. You will have to only convert excel file into sql or csv form and import it into your database.

index.php: In this file I have used Ajax and Jquery Library and some Php code. I have used JavaScript to getting data of pincode, courier name, sate and city from pin_check.php using help of Ajax. It also displays the returned HTML of pin_ckeck.php file.

<html>
<head>
<title>Indian pincode search with location and courier services</title>
<script type="text/javascript" src="script.js"></script>
<link rel="stylesheet" href="style.css" />
<script type="text/javascript" 
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){
$("#check").click(function() {
var name = $('#name').val();
if(name=="")
{
$("#disp").html("");
}
else
{
$.ajax({
type: "POST",
url: "pin_check.php",
data: "name="+ name ,
success: function(html){
$("#disp").html(html);
}
});
return false;
}
});
});
</script>

</head> 
 
<body>

<section>
  
<h1>Indian Pincode search with location and courier service</h1><br>

<center>

<form method="post">
<b style="color:white;">PINCODE SEARCH:</b>
<input  id="name" type="text" name="name" />
<input  id="check" type="submit" name="check" value="check" /></br>
</form>
</center>
  <center>
  <div class="tbl-content">
    <table cellpadding="0" cellspacing="0" border="0">
      <tbody>
        
        <h2><?php echo @$_GET['blank']; ?> </h2>
        <div id="disp"></div>
        
        
      </tbody>
    </table>
  </div>
</center>
</section>
</body>
</html>

pin_check.php:

In this file I have used MySql query to get data from Pincode table to display pincode, courier name, city, state on page using Ajax and Jquery.

<?php

$con = mysqli_connect("localhost","root"," ","indianpincode");
if(isset($_POST['name']))
{
$name=$_POST['name'];


$get="select * from Pincode where pincode='$name' ";
$query=mysqli_query($con,$get);
$row=mysqli_num_rows($query);

if($row==0)
{
echo "<h2 style='color:white;' >
Courier Company are not providing delivery services at this Pincode: 
<span style='color:red;'>$name</span></h2>";
}
else{

echo"   
<tr style='width:100%'>
<td style='width:15% color:#f51c4f;'><h3 style='color:black;'>PINCODE</h3></td>
<td style='width:15%'><h3 style='color:black;'>COURIER COMPANY</h3></td>
<td style='width:15%'><h3 style='color:black;'>CITY NAME</h3></td>
<td style='width:15%'><h3 style='color:black;'>STATE NAME</h3></td>
<td style='width:15%'><h3 style='color:black;'>STATE CODE</h3></td>
<td style='width:15%'><h3 style='color:black;'>COD</h3></td>
</tr>";        
while($row1 = mysqli_fetch_array($query)){
    $pincode = $row1['pincode'];
    $courier = $row1['courier_company'];
    $cityname = $row1['city_name'];
    $statename = $row1['state_name'];
   $statecode = $row1['state_code'];
     $status = $row1['cod'];

    echo"   
        <tr style='width:100%'>
          <td style='width:15%'>$pincode</td>
          <td style='width:15%'>$courier</td>
          <td style='width:15%'>$cityname</td>
          <td style='width:15%'>$statename</td>
          <td style='width:15%'>$statecode</td>
          <td style='width:15%'>$status</td>
        </tr>";

}
}

}
?>