Created
September 15, 2017 08:06
-
-
Save Mauryashubham/ab58920763f09d02925c8e470f93187b to your computer and use it in GitHub Desktop.
Simple Live Search Using Ajax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
@author : Shubham Maurya, | |
Email id : [email protected] | |
**/ | |
require_once 'db/dbconfig.php'; | |
if(isset($_POST['add_text'])) | |
{ | |
$name=$_POST['add_text']; | |
try | |
{ | |
$stmt=$DBcon->prepare("SELECT * FROM register WHERE name LIKE :name"); | |
$stmt->execute(array(':name'=>'%'.$name.'%')); //PLACEHOLDER ' : ' | |
//$data_f=$stmt->fetch(PDO::FETCH_ASSOC); | |
if($stmt->rowCount()>0) | |
{ | |
while ($row=$stmt->FETCH(PDO::FETCH_ASSOC)) | |
{ | |
echo "Name : ".$row['name']."<br>"; | |
echo "Email : ".$row['email']."<br>"; | |
echo "Mobile : ".$row['mobile']."<br>"; | |
echo "<hr>"; | |
} | |
} | |
else | |
{ | |
echo "No Match Found"; | |
} | |
} | |
catch (PDOException $e) | |
{ | |
echo $e->getMessage(); | |
} | |
$small_Id=$_POST['add_text']; | |
$sletter=strtoupper($small_Id); | |
//echo $sletter; | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- phpMyAdmin SQL Dump | |
-- version 4.7.0 | |
-- https://www.phpmyadmin.net/ | |
-- | |
-- Host: 127.0.0.1 | |
-- Generation Time: Sep 15, 2017 at 09:17 AM | |
-- Server version: 10.1.22-MariaDB | |
-- PHP Version: 7.1.4 | |
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; | |
SET AUTOCOMMIT = 0; | |
START TRANSACTION; | |
SET time_zone = "+00:00"; | |
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; | |
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; | |
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; | |
/*!40101 SET NAMES utf8mb4 */; | |
-- | |
-- Database: `food` | |
-- | |
-- -------------------------------------------------------- | |
-- | |
-- Table structure for table `register` | |
-- | |
CREATE TABLE `register` ( | |
`id` int(11) NOT NULL, | |
`name` varchar(250) NOT NULL, | |
`password` varchar(250) NOT NULL, | |
`mobile` bigint(255) NOT NULL, | |
`email` varchar(255) NOT NULL | |
) ENGINE=InnoDB DEFAULT CHARSET=latin1; | |
-- | |
-- Indexes for dumped tables | |
-- | |
-- | |
-- Indexes for table `register` | |
-- | |
ALTER TABLE `register` | |
ADD PRIMARY KEY (`id`); | |
-- | |
-- AUTO_INCREMENT for dumped tables | |
-- | |
-- | |
-- AUTO_INCREMENT for table `register` | |
-- | |
ALTER TABLE `register` | |
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;COMMIT; | |
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; | |
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; | |
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
@author : Shubham Maurya, | |
Email id : [email protected] | |
**/ | |
$DB_host = "localhost"; | |
$DB_user = "root"; | |
$DB_pass = ""; | |
$DB_name = "food"; | |
try | |
{ | |
$DBcon = new PDO("mysql:host={$DB_host};dbname={$DB_name}",$DB_user,$DB_pass); | |
$DBcon->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
// echo "Done.."; | |
} | |
catch(PDOException $e) | |
{ | |
echo "ERROR : ".$e->getMessage(); | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Get Email Address</title> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> | |
<script type="text/javascript"> | |
// For Small Letter | |
function small_letter() | |
{ | |
var addd=document.getElementById("address").value; //Get value from text using ID | |
if(addd) | |
{ | |
$.ajax({ //Use Ajax | |
type: 'POST', | |
url: 'address_ajax.php', //Ajax File | |
data: { | |
add_text:addd, | |
}, | |
success: function (data) { | |
$( '#add_status' ).html(data); | |
} | |
}); | |
} | |
else | |
{ | |
$( '#add_status' ).html("No Data Typed.."); | |
return false; | |
} | |
} | |
</script> | |
<style type="text/css"> | |
.margin_t | |
{ | |
margin-top: 15px; | |
} | |
.div_1 | |
{ | |
text-align: -webkit-center; | |
margin-top: 150px; | |
} | |
.text_center | |
{ | |
text-align: -webkit-center; | |
} | |
.box | |
{ | |
box-shadow: 0 4px 10px 0 rgba(0,0,0,0.2), 0 4px 20px 0 rgba(0,0,0,0.19); | |
padding: 50px; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-md-8 col-md-offset-2 text_center"> | |
<div class="box"> | |
<h2>GET EMAIL ADDRESS</h2> | |
<label>Enter Name of the Person, and get the Email-Id</label><br> | |
<input type="text" id="address" class="margin_t" onkeyup="small_letter();" name="add"><br> | |
<label>DETAILS : </label> | |
<br> | |
<span id="add_status" style="color:red;font-size: 12px;""></span> | |
</div> | |
</div> | |
</div> | |
</div> | |
<div> | |
<img src="add.png" alt="add"> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment