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

  • SEARCH
  • Home
  • 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 3492018
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:42:26+00:00 2026-05-18T11:42:26+00:00

I’m trying to streamline my login system by using ajax to handle to back

  • 0

I’m trying to streamline my login system by using ajax to handle to back and form requests to the server. I want to POST my form data to a PHP page, then return true/false and ‘Not Enough Data’ if the correct parameters didn’t get passed.

My problem is that my AJAX request isn’t sending the data that I’m giving it to send.

Here is my JavaScript function:

function confirm_login()
{
   val_UName = document.login_form.username.value;
   val_Pwd = document.login_form.password.value;

   var result = null;
   var scriptUrl = "login_confirm.php";
   $.ajax({
     url: scriptUrl,
     type: 'post',
     data: ({username : val_UName, password : val_Pwd}),
     dataType: 'html',
     async: false,
     success: function(data) {
         result = data;
     }
   });
   result = result.split('|');
   if(result[1] == 'true')
     window.location = "index.php";
   else
     alert('Could not log you in!\n\n'+result[0]);
}

This function is called in the onclick event of the submit button on the form. Now, I’ve used the debug tools in Chrome and I KNOW that val_UName and val_Pwd are getting the form values. So it’s definitely a breakdown between here and the login_confirm.php

Just for completeness’ sake, here’s what’s going on in login_confirm.php (I left out the lines that are connecting to the DB and closing the connection):

$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);

if($username == '' || $password == '')
      echo 'Not Enough Data|';

$login_query = "SELECT * FROM users WHERE u_name = '$username' AND pwd = '$password'";
$result = mysql_query($login_query);
$result_rows = mysql_num_rows($result);

if($result_rows > 0)
{
   session_start();
   $row = mysql_fetch_assoc($result);
   $_SESSION['loggedin'] = true;
   $_SESSION['uname'] = $row['u_name'];
   $_SESSION['uID'] = $row['pkid'];
   $_SESSION['email'] = $row['email'];
   $_SESSION['roleID'] = $row['fk_roleid'];
   echo 'true';
}
else
{
   echo 'false';
}

Anyone know what’s going on here or seen anything like this before?

PS. I’ve even tried changing to using GET and that still doesn’t work…

  • 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-18T11:42:27+00:00Added an answer on May 18, 2026 at 11:42 am
       result = result.split('|');
       if(result[1] == 'true')
         window.location = "index.php";
       else
         alert('Could not log you in!\n\n'+result[0]);
    

    is run before the callback returns.

    Try putting that logic inside the success callback or define a success function with that logic inside.

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

Sidebar

Related Questions

I want to construct a data frame in an Rcpp function, but when I
I'm trying to create an if statement in PHP that prevents a single post
I am using Paperclip to handle profile photo uploads in my app. They upload
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.