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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:48:14+00:00 2026-06-14T06:48:14+00:00

I’m using WAMP on a project and am having some difficulties. Basically, I want

  • 0

I’m using WAMP on a project and am having some difficulties. Basically, I want to click a form submit button which calls a function which requests some data in php.
My functions

/**********************************************************************************/
//USER LOG IN
$('#cSignIn').click(function(){
    //Get User name and password

    var uname = $('#uName').val();
    var pword = $('#pWord').val();

    loginRequest(uname, pword);

    $('.formList').hide();
    $('#information').show();
    return false;   
});

//LOGIN REQUEST
function loginRequest(uName, pWord){
    if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
             xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    xmlhttp.onreadystatechange=function(){
        if (xmlhttp.readyState==4 && xmlhttp.status==200){
            document.getElementById("rText").innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET","login.php?Username=" + uName +"&Password=" + pWord ,true);
    xmlhttp.send();

    return false;
} 

When I try to return the value of rText (my div) using $(‘#rText’).val(); OR $(‘#rText’).text(); it is not what I’m expecting it to be. The php code echos a number, the code for login.php is follows

<?php
$con = mysql_connect("localhost:3306","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("Library", $con);

$username=$_GET["Username"];
$password=$_GET["Password"];
$result = mysql_query("SELECT * FROM Customers");
$success = 0;

while($row = mysql_fetch_array($result))
  {
    if($username==$row['Username']) 
        if($password==$row['Password']) 
            if($row['Admin'] == true)
            {
                $success = 1;
            }
            else
            {
                $success = $row['Id'];
            }

  }
echo $success;

mysql_close($con);
?> 

Again, when I check the value of rText in either of the functions involved, the value is not expected. However, when I exit the function the value is valid.

How can I have the correct value in rText right after the return from function loginRequest?

  • 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-14T06:48:16+00:00Added an answer on June 14, 2026 at 6:48 am

    First, you can not use $(‘#rText’).val() for a Div, only Form inputs, you should use $(‘#rText’).html() instead

    Second, to make your life easier…you can widdle down your Login Request function quite a bit using ajax. Trust me, its not hard to get a grasp of. Here all you need to make an ajax request.

    //LOGIN REQUEST
    function loginRequest(uName, pWord) {
    
    
        $.ajax({
            type: "POST", //Post or Get
            url: "/login.php", //PHP page to post to
            data: "Username=" + uName +"&Password=" + pWord, // The values you want to send along to PHP Page
            dataType: "script", // This allows your PHP echo to be actual Javascript / Jquery
    
         });        
    }
    

    And your PHP success functions would be this

    while($row = mysql_fetch_array($result))
      {
        if($username==$row['Username'])
            if($password==$row['Password'])
                if($row['Admin'] == true)
                {
                    $success = "$('#rText').html('1')"; //Echo as Jquery
                }
                else
                {
                    $success = "$('#rText').html('" + $row['Id'] + "')"; // Echo as Jquery
                }
    
      }
    echo $success;
    

    Easy enough right??

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

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.