php - ajax doesn't check email availability -


i want check email availability, wrong here. inside form have:

<input id="inpmail" name="email" type="text" placeholder="e-mail">   

js

$(document).ready(function() {     $("#inpmail").change(function() {          var mail = $("#inpmail").val();         var msgbox = $("#status");  //`status` div          if (mail.length > 4) {             $("#status").html('<img src="img/loader.gif" align="absmiddle">&nbsp;checking availability...');  //this works              $.ajax({                   type: "post",                   url: "ajax.php",  // file in same folder                 data: "mail="+ mail,                   success: function(msg) {                       $("#status").ajaxcomplete(function(event, request){                          if (msg == 'ok') {                              msgbox.html('<img src="img/available.png" align="absmiddle">');  //doesn't work                         }                           else {                               msgbox.html(msg);  // doesn't work                         }                       });                 }              });          }         else {             $("#status").html('<font color="#cc0000">please enter atleast 5 letters</font>');  //this works         }         return false;     }); }); 

ajax.php

$conn = mysql_connect("localhost","root","") or die("database not connected");  // message never appears $db = mysql_select_db("vedic", $conn) or die("database not connected");   if (isset($_post['inpmail'])) {     $mail = $_post['inpmail'];     $sql = mysql_query("select id members email='$mail'");      // db named `vedic`, table `members` fields `id` , `email`        if (mysql_num_rows($sql))     {         echo '<strong>'.$mail.'</strong> in use.';     }     else     {         echo 'ok';     } } 

replace javascript code below,

$(document).ready(function() {     $("#inpmail").change(function()      {          var mail = $(this).val();         var msgbox = $("#status");  //`status` div          if(mail.length > 4)         {             msgbox.html('<img src="img/loader.gif" align="absmiddle">&nbsp;checking availability...');  //this works              $.ajax({                 type: "post",                   url: "ajax.php",  // file in same folder                 data: "mail="+ mail,                   success: function(msg)                 {                       if(msg == 'ok')                     {                          msgbox.html('<img src="img/available.png" align="absmiddle">');  //doesn't work                     }                       else                       {                           msgbox.html(msg);  // doesn't work                     }                   }             });         }         else         {             $("#status").html('<font color="#cc0000">please enter atleast 5 letters</font>');  //this works         }         return false;     }); }); 

you have }); @ end, repeating same selector defined globally.

php

you sending mail params posted email address , checking inpmail not return true ever.

in php replace

if (isset($_post['inpmail'])) 

with

if (isset($_post['mail'])) 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -