Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6692431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:52:01+00:00 2026-05-26T05:52:01+00:00

Code Logic: 1) User types in username and password, user clicks submit. 2) jQuery

  • 0

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

class1.php

$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() . "<br>IN QUERY: " . $sql);

if (mysql_num_rows($result) > 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;
        }
    }
?>

index.html:

<script src="http://code.jquery.com/jquery-latest.js"></script>

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

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

    var data = 'name=' + name.val() + '&email=' + email.val() + '&website='
    + website.val() + '&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;
    });
});
</script>

<input type="text" id="username" name="username" />
<input type="password" id="password" name="password" />
<input type="submit" id="submit" />
<div class="loading"></div>
<div id="display"></div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:52:01+00:00Added an answer on May 26, 2026 at 5:52 am

    Ajax is effectively a “blind client”. So, think of what you would see if you were to manually view the php script, and interpret that as what your ajax callback would be parsing.

    Having said that, the “0/1” return you’re looking for is dependent on one (of many) echos going on in your script (most notably the following):

    echo "new user created and logged in";
    

    if you want the ajax callback to recognize a 0/1, this would need to only echo a “1” (not verbiage), where as errors would simply return a “0” (such as your or exit("ERROR...).

    EDIT

    Also, looking further, your var data = 'name=' component (assuming you want it to align with the PHP $_POST["username"]) should probably be renamed to var data ='username=' (the data property of the ajax call is what’ populating your PHP’s $_POST variables, so names need to align).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code in an IAuthorizationFilter which redirects the user to a login
Possible Duplicate: php headers already sent error I have attached my code which am
I've created a login submit form in HTML but for some reason user/password autocompletion
I'm using the following piece of code to login a user via Ajax. //Capture
here is the code <?php session_start(); if(!isset($_SESSION['user_name'])) { header('Location: login.php'); } $conn = mysql_connect(localhost,
I need syntax help with the following code logic: I have a code block
In an MVC web app, where is the right place to put the code/logic
How would you explain to a non-technical person why writing code (business-logic) behind the
I'm currently working in a piece of code where both logic and data access
As per my understanding stateless session beans are used to code the business logic.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.