2 Replies - 764 Views - Last Post: 25 February 2011 - 12:20 PM

#1 Guest_liquid_chaos*


Reputation:

ajax not working problem

Posted 24 February 2011 - 03:15 PM

hi i dont know what ive done wrong but i am trying to use yui ajax to display if a username is taken or not but it wont come up on the page at all

signup.php
<?php //signup.php with yui
include_once 'header.php';

echo <<<_END
<script src="yahoo-min.js"></script>
<script src="event-min.js"></script>
<script src="connection-min.js"></script>
<script>

function checkUser(user)
{
    if(user.value == '')
    {
        document.getElementById('info').innerHTML = ''
        return
    }
    
    params = "user=" +user.value
    callback = {success:successHandler, failure:failureHandler }
    request = YAHOO.util.Connect.asyncRequest('POST', 'checkuser.php, callback, params)
}

function successHandler(o)
{
    document.getElementById('info').innerhtml = o.responseText;
}

function successHandler(o)
{
    document.getElementById('info').innerHTML = o.status + " " + o.statusText;
}

</script>

<hr> Sign Up Form</hr>
_END;

$error = $user = $pass = "";
if (isset($_SESSION['user'])) destroySession();

if (isset($_POST['user']))
{
    $user = sanitizeString($_POST['user']);
    $pass = sanitizeString($_POST['pass']);
    
    if ($user == "" || $pass == "")
    {
        $error = "Not all fields were entered<br /><br />";
    }
    else
    {
        $query = "SELECT * FROM members WHERE user='$user'";
        
        if(mysql_num_rows(queryMysql($query)))
        {
            $error = "That Username is already taken<br /><br />";
        }
        else
        {
            $query = "INSERT INTO members VALUES('$user', '$pass')";
            queryMysql($query);
        }
        
        die("<h4>Account created</h4Please Log in.");
    }
}

echo <<<_END
<form method='post' action='signup.php'>$error
Username <input type='text' maxlength='16' name='user' value='$user'
    onblur='checkUser(this)'/><span id='info'></span><br />
Password <input type='password' maxlength='16' name='pass'
    value='$pass' /><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<input type='submit' value='Signup' />
</form>
_END;
?>




checkuser.php


<?php //checkuser.php
include_once 'functions.php';

if (isset($_POST['user']))
{
    $user = sanitizeString($_POST['user']);
    $query = "SELECT * FROM members WHERE user='$user'";
    
    if (mysql_num_rows(queryMysql($query)))
        echo "<font color=red>&nbsp;&larr;Sorry, already taken</font>";
    else echo "<font color=green>&nbsp;&larr; Username Available</font>";
}
?>




as there are no errors im not sure where i have went wrong. any help would be appreciated

Is This A Good Question/Topic? 0

Replies To: ajax not working problem

#2 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1138
  • View blog
  • Posts: 7,105
  • Joined: 07-September 06

Re: ajax not working problem

Posted 25 February 2011 - 10:45 AM

One of the problems is likely because you have 2 successHandlers and no failureHandler functions:
function successHandler(o)
{
    document.getElementById('info').innerhtml = o.responseText;
}

function successHandler(o)
{
     document.getElementById('info').innerHTML = o.status + " " + o.statusText;
} 



I believe the second one was meant to be failureHandler:
function successHandler(o)
{
    document.getElementById('info').innerhtml = o.responseText;
}

function failureHandler(o)
{
     document.getElementById('info').innerHTML = o.status + " " + o.statusText;
} 



See if that makes a difference.
Was This Post Helpful? 2
  • +
  • -

#3 moopet  Icon User is offline

  • binary decision maker
  • member icon

Reputation: 339
  • View blog
  • Posts: 1,185
  • Joined: 02-April 09

Re: ajax not working problem

Posted 25 February 2011 - 12:20 PM

Also, why is the case of innerHTML changing back and forth?
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1