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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:09:21+00:00 2026-06-05T08:09:21+00:00

So i am attempting to learn some jquery to use in a form to

  • 0

So i am attempting to learn some jquery to use in a form to access a mysql database, here is the form:

<form class="loginform" id="loginform" name="loginform">
    <input type="email" id="login" name="login" placeholder="Login..." autofocus required /><br/>
    <input type="password" id="password" name="password" placeholder="Password..." required /><br/>
    <input type="submit" id="loginsubmit" name="loginsubmit" value="LOGIN"/><br/>
    <input type="submit" id="register" name="register" value="REGISTER"/><br/>
</form><!-- end loginform -->

I have a JS function and am using the $.submit() function and through the function defined as the parameter for $.submit() i have a call to $.ajax() like so:

function validateLogin(){
  $('#loginform').submit(function() {      
    $.ajax({
      url: "./validateLogin.php", 
      processData: false,
      data: {
        login: $("#login").val(), 
        password: $("#password").val()
      }, 
      success: function (result){
        alert($('#login').val());
        alert(result);
      }
    });
  });
}

notice the line that reads processData: false,
and finally here is the php script that is called by the $.ajax() method in the url setting:

<?php
$verified = FALSE;
$login = $_POST["login"];
$password = $_POST["password"];

$con = mysql_connect(host, user, pass) or die(mysql_error());
mysql_select_db(db, $con) or die(mysql_error());

$result = mysql_query("SELECT * FROM logins") or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
  if ($row[login] == $login) {
    $verified = TRUE;
  }
}
?>

<html>
    <body>
        <?php echo($verified); ?>
    </body>
</html>

There are a few things not working, I can’t get anything to happen with the exception of the form data being appended to the url( the url will look something like this after submitting: http://localhost/index.htmlqlogin=aloginname&password=apassword&login=LOGIN, it is also adding the name: value pair for my submit button to the query string for some reason), and it is my understanding from reading HERE (see the data setting) that with processData: false this shouldn’t even be happening.

Also I can’t get the success: function() to fire the alerts (i have also tried throwing an alert in beforeSend: function() and that won’t fire either.

I kinda understand jQuery but not entirely a i’m relatively new to it, but what i understand about the code i’ve written is that in the JS function i’m attaching an event handler to the form(? – not an element of the form), and in the function that that event handler will execute i am making a call to the $.ajax() method, that sends the data to a url and on successful completion of that processes the function defined in the success: setting of the $.ajax() method. then in my php script i am connecting to mysql, querying it, checking to see if the login from the form matches an entry in the db, if it does a boolean is changed to true and finally the value of the boolean is echoed inside a <html> tag, however i’m not sure about how to display that html data.

so thats my problem in a nutshell. any guidance would be greatly appreciated!
feel free to correct me if i am misunderstanding anything about the process as described above. thanks again.

  • 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-05T08:09:22+00:00Added an answer on June 5, 2026 at 8:09 am

    Several things to remark.

    1- Make sure the path ./validateLogin.php is right.

    2- I don’t know if you do already, but if you dont use Firebug, the coolest addon for debugging when developing a website. It will save you hours of work literally and help you with errors involving javascript.

    3- The most common use of ajax is to either post or bring data. Either simple string like “done” or “error“, or serialized data like JSON.(see JSON). If you need to output an array or an object use json_encode function in PHP.

    Here is some code for you to try, it worked for me.

    On PHP side

       $result = mysql_query("SELECT * FROM logins") or die(mysql_error());
       while ($row = mysql_fetch_array($result)) {
           if ($row[login] == $login) { 
             $verified = TRUE;
           }
       }
       if ($verified){
            echo 'TRUE';  // This could be anything you want, an array, an object, numbers or a string
       }else{
            echo 'FALSE';
       }
    

    On Javascript Side

    $(document).ready(function(){ // Everything is encapsuled in the ready function in order to wait for the page to load completely.
        $.ajax({
            url: './validateLogin.php', 
            type: 'POST',
            success: function(result){
    
                if(result == 'TRUE'){
                    alert('Verified!');                         
                }else{
                    alert('Not verified!');                             
                }
    
            }
        });
    });
    

    I know you were trying to output the and tags too, but remember that javascript and ajax is meant to smoothly change the existen layout. So you don’t really want to bring huge amounts of HTML code in your requests. You should prepare your layout with HTML and PHP first and then use javascript and ajax only to bring important data or things you need to change on the fly.

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

Sidebar

Related Questions

Greetings from some noob trying to learn JQuery, I am attempting to make it
I'm attempting to learn some flex/bison, and I'm reading Flex & Bison by John
I'm a Perl programmer who's attempting to learn Python by taking some work I've
I am attempting to run some AppleScript in the terminal, just to learn how
Im attempting to learn powerscript and was wondering what i'm doing wrong here >
I am attempting to learn to use RapidMiner, and my boss wants me to
I am working on a class that utilises a UdpClient, and attempting to learn/utilise
I'm attempting to learn some Python and Tkinter. The sample code below is intended
I am attempting to learn Django and Javascript/jQuery for a personal project. I want
I am attempting to learn J and the book I am using says this

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.