<form> <label for="text_email">E-mail:</label> <input id="text_email" type="email" > <script type="text/javascript" charset="utf-8" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"> $(document).ready(function(){ $('#text_email').keyup(function(){ email($(this).val()); }); }); function email(str){ $.post('checkmail.php',{ email: str}, function(data){ $('#check_email').html(data.returnValue); }, 'json'); } </script> <label for="text_email" id="check_email"></label> </form>
<?php if(isset($_POST['email'])) { try { $pdo=new PDO('mysql:host=localhost;dbname=class;charset=utf-8', 'root'); } catch(PDOException $e) { echo 'Failed: '.$e->getMessage(); } $stmt=$pdo->prepare('SELECT email FROM class where email=:email LIMIT 1'); $stmt->execute(array(':email'=>$_POST['email'])); if($stmt->rowCount()>0) { $check='E-mail cannot be use.'; } else { $check='E-mail can be use.'; } echo json_encode(array('returnValue'=>$check)); } ?>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)