Here we will show how can live check email exists and not using Ajax, JQuery , PHP and MySql. This is a common feature in most of website available online.
The PHP script matches the user input against the database and returns the reponse.
Below is a sample table.
--
-- Table structure for table `user_info`
--
CREATE TABLE `user_info` (
`id` int(11) NOT NULL,
`name` varchar(20) DEFAULT NULL,
`email` varchar(255) NOT NULL,
`age` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `user_info`
--
INSERT INTO `user_info` (`id`, `name`, `email`, `age`) VALUES
(1, 'Amit', 'amit@gmail.com', 20),
(2, 'Anil', 'anil@hotmail.com', 21),
(3, 'Mahesh', 'mahesh@gmail.com', 20),
(4, 'Arvind', 'arvind@outlook.com', 24),
(5, 'Amit', 'amit@gmail.com', 20),
(6, 'Vedant', 'vedant@yahoo.com', 21),
(7, 'Rajendra', 'rajendra@outlook.com', 23),
(8, 'Arvind', 'arvind@outlook.com', 24),
(9, 'Kuldeep', 'kuldeep@outlook.com', 19);
--
-- Indexes for table `user_info`
--
ALTER TABLE `user_info`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for table `user_info`
--
ALTER TABLE `user_info`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10;
COMMIT;
Now Create connection.php file to connect with database. Below is code.
Now create index.php file contains email input field.Below is code
Inflay.com | Check Email Already Exists Using JQuery Ajax PHP MySql
Check Email Already Exists Using JQuery Ajax PHP MySql
Below is Javascript code triggers Ajax call blur event of email input. $.ajax send email entered by the user along with the request for a PHP page.
Match Email against Database using PHP
Now Create check_input.php file executed as a result of the jQuery AJAX call. It compares database and user data to check email. Based on the availability status it will respond to the AJAX call.
Below is code.
0)
{
$result = " Email Not Available.";
}
else
{
$result = " Email Available.";
}
echo $result;
}
?>
OUTPUT
I hope this article helps you.
Thanks for visiting Inflay.com .