Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: AJAX: UserName is Available

  1. #1
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default AJAX: UserName is Available

    In AJAX in a Registration Form : to appear "UserName is Available" I must query the database upon after what event (PHP), user stop enters chars in Input Field ? If yes, what event is it this ? This AJAX & PHP code (both) is visible (source) from browser ?

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Take a look at this page:
    http://www.shawngo.com/gafyd/index.html

    You could modify the PHP script to use a Database instead of a CSV file very easily, but if you need help with that, let us know.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. The Following User Says Thank You to thetestingsite For This Useful Post:

    leonidassavvides (07-28-2009)

  4. #3
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default You mean needed change with DATABASE QUERY only the check.php ?

    You mean needed change with DATABASE QUERY only the check.php ?

    The jquery.js is it needed any change at all ?
    I must attach it to form webpage ?
    form.name="register" ,
    field.name="email"

  5. #4
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    have to delete anything unneeded from jquery.js ?

  6. #5
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default query error appear, is it ajax code without problems ?

    query error appear , is it ajax code without problems ?

    error
    "
    Unable to execute query. Please try again later. error3
    "
    at line 14 (attached check.php code)

    see at

    http://www.poliscarhire.com/customer...cBETA-ajax.php

    email(username) field to be checked ... thks again!

  7. #6
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    email addresses are appropriate for username form input field for this to work?

  8. #7
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    In the php code, you have to define the variable $CustomersTable either as a variable or just insert it into the code:

    Code:
     
    $CustomersTable = 'Customers';
    $queryajax = "SELECT * FROM $CustomersTable";
    Code:
     $queryajax = "SELECT * FROM `Customers`";
    Hope this helps.

    Edit: The rest of the files do not need to be changed. Just leave them as is. (it appears as though the ajax portion is working on the form field, it is just returning an php error.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  9. #8
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    please note

    $CustomersTable = 'Customers';

    is included in dbinfo.php file I include ...

    I tried below but after REMOVING die statement ...now ONLY
    Username Available
    shows whatever I insert...I use dmwr cs4 ...

    see attachments

  10. #9
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    Must be something about below $f declarations->
    How I declare a var only in a function valid ?

    $f = "n"; // outside function

    if (strtolower($username) == strtolower($row['email'])) { // in function
    $f = "y";
    break; // break works here

    seems $f=is always value of 'n'

    well ?

  11. #10
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    See if this works for you.

    Code:
    <?php
    error_reporting(6147); //change 6147 to 0 after testing. never use @ to suppress errors.
    
    function check_username($username) {
    
    include("../dbinfo.php");
    
    $linkidajax = mysql_connect($hostname,$username,$password) or die( "Unable to connect to Database Server. Please try again later.");  
    
    mysql_select_db($database,$linkidajax) or die( "Unable to select database.  Please try again later,");   // @
    
    $queryajax = "SELECT email,status FROM $CustomersTable WHERE status='active'";   
    
    //$CustomersTable=customers2; in `customers2`
    
    $resultajax = mysql_query($queryajax,$linkidajax) or die('Unable to execute query. Please try again later. error3');  
    
    // I removed and worked or die("Unable to execute query. Please try again later. error3");
    $count = @mysql_num_rows($resultajax); 
     // echo $count;$f = "n";
    			  
     for ($j=0;$j<$count;$j++) {
      $row = mysql_fetch_assoc($resultajax);
    
       if (strtolower($username) == strtolower($row['email'])) {  
       
       // $email == $row[1]      $row['email']         && $row['status'] == "active"
    	  $f = "y";
          break;
    	}
    				 
    } 
    				
    if ($f == "y") {
     return '<span style="color:#f00">Username Unavailable</span>';
    } 
    else {	
     return '<span style="color:#0c0">Username Available</span>';
    }
    
    mysql_free_result($resultajax);
    mysql_close($linkidajax);
    }
    
    echo check_username($_POST['username']); // call the check_username function and echo the results.$file,$file_in,
    ?>
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •