O'Reilly logo

Learning PHP, MySQL, and JavaScript by Robin Nixon

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

rnsignup.php (YUI version)

If you prefer to use YUI, here’s an alternative version of rnsignup.php (see Example 20-6). I have highlighted the main differences in bold type and, as you can see, it’s substantially shorter. Please refer to Chapter 19 for details on how the YUI Ajax implementation works.

Example 20-6. rnsignup.php (YUI version)
<?php // rnsignup.php (YUI version)
include_once 'rnheader.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',
        'rncheckuser.php', callback, params);
}

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

function failureHandler(o)
{
    document.getElementById('info').innerHTML =
        o.status + " " + o.statusText;
} </script> <h3>Sign up Form</h3> _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 rnmembers WHERE user='$user'"; if (mysql_num_rows(queryMysql($query))) { $error = "That username already exists<br /><br />"; } else ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required