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

The Archive Base Latest Questions

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

Hi everyone I am trying to submit a form without the page reloading, a

  • 0

Hi everyone I am trying to submit a form without the page reloading, a seemingly straightforward thing with AJAX, but I can’t seem to get any changes on my database. I have an alert set in my javascript to run if the AJAX was successful, and it seems to trigger every time, so I think the variables are, indeed, getting sent out of the AJAX, but when I get to join.php, I don’t think it remembers, and therefore doesn’t process correctly.

First of all, here is the relevant script.js:

$(document).ready(function () {
    //----SUBMIT---//
    $(".submit").click(function () {
        // validate and process form here  

        $('.error').hide();
        var studentEmail = $("input#studentEmail").val();
        if (studentEmail == "") {

            $("label#studentEmail_error").show();
            $("input#studentEmail").focus();
            return false;
        }

        var studentPassword = $("#studentPassword").val();
        var parentEmail = $("#parentEmail").val();
        var parentPassword = $("#parentPassword").val();
        var studentFirstName = $("#studentFirstName").val();
        var studentLastName = $("#studentLastName").val();
        var studentPhone = $("#studentPhone").val();
        var parentFirstName = $("#parentFirstName").val();
        var parentLastName = $("#parentLastName").val();
        var parentPhone = $("#parentPhone").val();


        var dataString = 'studentEmail=' + studentEmail 
                         + '&studentPassword=' + studentPassword 
                         + '&parentEmail=' + parentEmail 
                         + '&parentPassword=' + parentPassword 
                         + '&studentFirstName=' + studentFirstName 
                         + '&studentLastName=' + studentLastName 
                         + '&studentPhone=' + studentPhone 
                         + '&parentFirstName=' + parentFirstName 
                         + '&parentLastName=' + parentLastName 
                         + '&parentPhone=' + parentPhone;

        alert(dataString);

        $.ajax({
            type: "POST",
            url: "join.php",
            data: dataString,
            success: function () {
                alert("success");
            }
        });
        return false;
    });
});

Then join.php

if($_POST) {
    $studentEmail=$_POST['studentEmail'];
    $studentPassword=$_POST['studentPassword'];
    $parentEmail=$_POST['parentEmail'];
    $parentPassword=$_POST['parentPassword'];
    $studentFirstName=$_POST['studentFirstName'];
    $studentLastName=$_POST['studentLastName'];
    $studentPhone=$_POST['studentPhone'];
    $parentFirstName=$_POST['parentFirstName'];
    $parentLastName=$_POST['parentLastName'];
    $parentPhone=$_POST['parentPhone'];

    //create database connection
    $connection = mysql_connect("localhost","XXXX","XXXX"); 
        //in case database connection fails
        if(!$connection) {
            die("Database connection failed: ".mysql_error());
        }

        else{

        //select database to use
        $db_select = mysql_select_db("XXXX",$connection); 
            //in case database selection fails
            if (!$db_select) { 
                die("Database selection failed: " . mysql_error()); 
            } 

            else {

            //make sql query
              $sql = "INSERT INTO clients (`studentEmail`, 
                                                   `studentPassword`, 
                                                   `parentEmail`, 
                                                   `parentPassword`,
                                                   `studentFirstName`, 
                                                   `studentLastName`, 
                                                   `studentPhone`, 
                                                   `parentFirstName`, 
                                                   `parentLastName`, 
                                                   `parentPhone`)
                    VALUES ('".$studentEmail."', 
                            '".$studentPassword"', 
                            '".$parentEmail."', 
                            '".$parentPassword."', 
                            '".$studentFirstName."', 
                            '".$studentLastName."', 
                            '".$studentPhone."', 
                            '".$parentFirstName."', 
                            '".$parentLastName."', 
                            '".$parentPhone."')";

                //set results to variables
                $result = mysql_query($sql);

                //in case query fails
                if (!$result) { 
                    die("Database query failed: " . mysql_error()); 
                } 
            }
        }

}

else {
    echo "FAIL";
}
  • 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-27T11:32:18+00:00Added an answer on May 27, 2026 at 11:32 am

    Try to change the $.post() call into this:

    $.ajax({
        type: "POST",
        url: "join.php",
        data: dataString,
        success: function(data) {
          alert ("Success: "+ data);
        }
    });
    

    And, at the beginning of PHP code, place this:

    var_dump($_POST);
    

    This way, the alert message will display the data received from PHP.

    UPDATE:

    Since I see nobody here is seeing the hugest security risk with that code, I add it here:

    Be very sure that you pass every single string from post through mysql_real_escape_string() before adding it inside the query!

    What if anybody posts this as his email address??:

    '); DROP TABLE clients; -- 
    

    UPDATE:

    I double-checked documentation of jQuery.ajax() and jQuery.post(). While .post() is just a shortcut for .ajax(), their syntax is different:

    jQuery.post( url [, data] [, success(data, textStatus, jqXHR)] [, dataType] )
    jQuery.ajax( settings )
    

    (updated code above too).

    UPDATE:

    Try this code, that should work “out of the box”:

    The JavaScript:

    $(document).ready(function(){
        $(".submit").click(function() {  
    
            $('.error').hide();  
            var studentEmail = $("input#studentEmail").val();  
            if (studentEmail == "") {  
                $("label#studentEmail_error").show();  
                $("input#studentEmail").focus();  
                return false;  
            }
    
            var dataString = {
                studentEmail : studentEmail,
                studentPassword : $("#studentPassword").val(),
                parentEmail : $("#parentEmail").val(),
                parentPassword : $("#parentPassword").val(),
                studentFirstName : $("#studentFirstName").val(),
                studentLastName : $("#studentLastName").val(),
                studentPhone : $("#studentPhone").val(),
                parentFirstName : $("#parentFirstName").val(),
                parentLastName : $("#parentLastName").val(),
                parentPhone : $("#parentPhone").val(),
            };
    
            $.ajax({
                type: "POST",
                url: "join.php",
                data: dataString,
                success: function(data) {
                    alert ("success: "+ data);
                }
            });
    
            return false;
        });
    });
    

    The PHP code

    var_dump($_POST);
    echo "\n\n"; // Some white space here
    
    if($_POST) {
        $connection = mysql_connect("localhost","XXXX","XXXX"); 
        if(!$connection) {
            die("Database connection failed: ". mysql_error());
        }
        if (!mysql_select_db("XXXX",$connection)) { 
            die("Database selection failed: " . mysql_error()); 
        }
    
        // Read data from POST
        $studentEmail       = mysql_real_escape_string($_POST['studentEmail']);
        $studentPassword    = mysql_real_escape_string($_POST['studentPassword']);
        $parentEmail        = mysql_real_escape_string($_POST['parentEmail']);
        $parentPassword     = mysql_real_escape_string($_POST['parentPassword']);
        $studentFirstName   = mysql_real_escape_string($_POST['studentFirstName']);
        $studentLastName    = mysql_real_escape_string($_POST['studentLastName']);
        $studentPhone       = mysql_real_escape_string($_POST['studentPhone']);
        $parentFirstName    = mysql_real_escape_string($_POST['parentFirstName']);
        $parentLastName     = mysql_real_escape_string($_POST['parentLastName']);
        $parentPhone        = mysql_real_escape_string($_POST['parentPhone']);
    
        $sql = "INSERT INTO clients ".
            "(`studentEmail`, `studentPassword`, `parentEmail`, `parentPassword`, ".
            "`studentFirstName`, `studentLastName`, `studentPhone`, `parentFirstName`, ".
            "`parentLastName`, `parentPhone`) ".
            " VALUES ('$studentEmail', '$studentPassword', '$parentEmail', ".
            "'$parentPassword', '$studentFirstName', '$studentLastName', ".
            "'$studentPhone', '$parentFirstName', '$parentLastName', '$parentPhone')";
    
        $result = mysql_query($sql);
        if ($result) { 
            echo "Database query successful!";
        }
        else {
            die("Database query failed: " . mysql_error()); 
        } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello everyone I been trying get php uploader working but having a lot of
Everyone, I am trying to do read more feature with JQuery's slideToggle thing but
Hey everyone I am trying to .submit some values with ajax response and i
Hey everyone, I am trying to run the following program, but am getting a
I am trying to bulk disable all the submit buttons present in my form.
everyone. I am an experienced C programmer trying to get adjusted to C++. I
Hi everyone Im trying to get the value of textbox whenever the user clicks
I'm trying to list everyone in a security group in an active directory without
Hello everyone iam trying to open a aspx page in a dialog box window
Hi everyone I'm trying to think about how to get some database designs done

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.