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 8313371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:28:13+00:00 2026-06-08T20:28:13+00:00

I’m writing a jquery login. If the php login script (checklogin.php) echoes true then

  • 0

I’m writing a jquery login. If the php login script (checklogin.php) echoes “true” then my jquery page is supposed to give an alert. When I run a login.php (that doesn’t use jquery) it sends the request to checklogin.php which echoes “true” however if I use my jquery login script to send the login info to checklogin.php, the alert I trace back says “false”.

$('#login').click(function(e){
      $.getJSON("http://www.hedonsoft.com/game/login.php",{username: $("#username").val(), password: $("#password").val()},function(data){
         if(data==true){
            alert(data.boolean);
            //$('#logindiv').slideUp();
            //$('#gamediv').show(); 
            //$('#registerdiv').hide();
            //$('#gameheader').html(data['username']);
         }else{
            alert("false");
         }
      });
});

<?php
header('Access-Control-Allow-Origin: *');
$host="localhost"; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name="hedonsof_conflict"; // Database name 
$tbl_name="members"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){

// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword"); 
$json = array('boolean' => 'true', 'jsonUser' => $myusername);
echo "true";
}
else {
echo "Wrong Username or Password";
}
?>

So long story short, when I try to login from a regular php page the value I trace is true, when I try to login from a jquery page the value I trace is false;

EDIT:

<?php
...
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){

// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword"); 
$json = array('boolean' => true, 'jsonUser' => $myusername);
echo true;
}
else {
echo "Wrong Username or Password";
}
?>

And my jQuery…

$('#login').click(function(e){
      $.getJSON("http://www.hedonsoft.com/game/login.php",{username: $("#username").val(), password: $("#password").val()},function(data){
         if(data){
            alert("true");
            //$('#logindiv').slideUp();
            //$('#gamediv').show(); 
            //$('#registerdiv').hide();
            //$('#gameheader').html(data['username']);
         }else{
            alert(data); // shows null
         }
      });
});

With json_encode, boolean’s value is returned null

$('#login').click(function(e){
       $.getJSON("http://www.hedonsoft.com/game/login.php",{username: $("#username").val(), password: $("#password").val()},function(data){
          if(data.boolean == "true"){
             alert("true");
             //$('#logindiv').slideUp();
             //$('#gamediv').show(); 
             //$('#registerdiv').hide();
             //$('#gameheader').html(data['username']);
          }else{            alert(data);
          }
       }); });
<?php
...
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword"); 
$json = array('boolean' => true, 'jsonUser' => $myusername);
echo json_encode($json);
}
...
?>
  • 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-06-08T20:28:14+00:00Added an answer on June 8, 2026 at 8:28 pm

    Use true, not 'true'. 'true' is a string, and you want a boolean:

    $json = array('boolean' => true, 'jsonUser' => $myusername);
    

    Also, never write == true.

    if(data==true) {

    Okay, now the problem is:

    $json = array('boolean' => true, 'jsonUser' => $myusername);
    echo true;
    

    Don’t echo true, echo json_encode($json).

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
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 would like to count the length of a string with PHP. The string
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.