using jquery to process a php script based on returned values
<p>Code Logic:<br>
 1) User types in username and password, user clicks submit.<br>
 2) jQuery script pulls the php script below.<br>
 3) jQuery determines which php value is returned.<br>
 4) if value 1 is returned, jquery and php will process what's in the if statement.<br>
 5) if value 0 is returned, jquery and php will process whats in the else statement.<br>
How do I successfully make the code below work alongside the logic above? I can't seem to make a connection in my mind.</p>

<p>class1.php
    

<pre><code>$email = mysql_real_escape_string(strip_tags($_POST["username"]));
$password = sha1($_POST["password"]);
$sql = "SELECT * FROM users WHERE username = '{$email}' AND password = '{$password}'";
$result = mysql_query($sql) or exit("ERROR: " . mysql_error() . "&lt;br&gt;IN QUERY: " . $sql);

if (mysql_num_rows($result) &gt; 0) {
    return 1;
    $row = mysql_fetch_array($result);
    $_SESSION["userid"] = $row['user_pid'];
} else {
    return 0;
    $userid_generator = uniqid(rand(), false);
    mysql_query("INSERT INTO users (user_pid, email, password, datetime_registered, is_leader) VALUES ('$userid_generator', '{$email}', '{$password}', NOW(), 'no')");
    $id = mysql_insert_id();
        $leaders = mysql_query("SELECT * FROM users WHERE is_leader LIKE '%yes%'");
        while($rows = mysql_fetch_array($leaders)) {
            if ($rows['is_leader'] == 'yes') {
                $leader_id = $rows['user_pid'];
                mysql_query("INSERT IGNORE INTO friends (node1id, node2id, friends_since, friend_type)
                VALUES('$leader_id', '$userid_generator', NOW(), 'full')");
                echo "new user created and logged in";
                }
    $_SESSION["userid"] = $userid_generator;
        }
    }
?&gt;
</code></pre>

<p>index.html:</p>

<pre><code>&lt;script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;

&lt;style type="text/css"&gt;
.loading {
    float:right; 
    background:url(img/ajax-loader.gif) no-repeat 1px; 
    height:28px; 
    width:28px; 
    display:none;
}
&lt;/style&gt;

&lt;script type="text/javascript"&gt;
$(document).ready(function() {
    $('#submit').click(function () {
    var username = $('input[username=username]');
    var password = $('input[password=password]');

    var data = 'name=' + name.val() + '&amp;email=' + email.val() + '&amp;website='
    + website.val() + '&amp;comment='  + encodeURIComponent(comment.val());

    $('.text').attr('disabled','true');
    $('.loading').show();

        $.ajax({
            url: "processing/class1.php", 
            type: "POST",
            //pass the data
            data: data,     
            //Do not cache the page
            cache: false,
            //success
            success: function (html) {              
                //if process.php returned 1/true (send mail success)
                if (html==1) {                  
                   alert('success');

                //if process.php returned 0/false (send mail failed)
                } else { alert('failure');
            }
        });
        return false;
    });
});
&lt;/script&gt;

&lt;input type="text" id="username" name="username" /&gt;
&lt;input type="password" id="password" name="password" /&gt;
&lt;input type="submit" id="submit" /&gt;
&lt;div class="loading"&gt;&lt;/div&gt;
&lt;div id="display"&gt;&lt;/div&gt;
</code></pre>
