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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:16:30+00:00 2026-05-24T17:16:30+00:00

I was chasing after JSON as a method to do this, but I’m wondering

  • 0

I was chasing after JSON as a method to do this, but I’m wondering if I should have been looking in a different direction. I’ll tackle this as simply as possible.

Jquery from “page1.php”

$(".button").click(function() {

       var name = "Jeremy";
       var car = "Saturn";
       var color = "blue";
       var state = "Mississippi";
// I need all four of these to get passed over to PHP in the following ajax

          $.ajax({
            url: "page2.php",
            //dataType: '???????',
            type: 'POST',
            data: 'mydata=' + ????????,

                success: function(result) {
                alert(result);

                }
            });

      });

So there are four jquery variables that I’ve fudged. Now I need to hand them over to page2.php for my backend PHP. Here is page2.php

if (filter_has_var(INPUT_POST, "mydata")) {

    $mydata = mysql_real_escape_string(filter_input(INPUT_POST,'mydata'));

// Here I need to turn these into variables, or just an array and then throw them into my SQL

mysql_query("INSERT INTO mysqldata (namefield, carfield, colorfield, statefield)
            VALUES ($name, $car, $color, $state)"); 

$sqlresult = mysql_insert_id;

if ($sqlresult != '') {
   echo "SQL successfully updated.";
}

}

Thus, my question is: What is the most effective method to pass the data to PHP, in this case?
There’s probably a simple answer here that I just don’t know. Can I turn those jquery variables into an array and hand them to PHP that way? Is JSON still the best way to go, and I just need to know how to convert it on the back end?

  • 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-24T17:16:32+00:00Added an answer on May 24, 2026 at 5:16 pm

    JavaScript/jQuery

    $(".button").click(function() {
    
        // create the data object
        var myData = {
            name : 'Jeremy',
            car : 'Saturn',
            color: 'blue',
            state: 'Mississippi'
        };
    
        $.ajax({
            url: "page2.php",
            //dataType: '???????',
            type: 'POST',
            data: myData,
            success: function(result) {
                alert(result);
            }
        });
    });
    

    PHP

    // check if the name has been posted, which means we have a submission to process
    if(isset($_POST['name'])){
        $query = sprintf("INSERT INTO mysqldata (namefield, carfield, colorfield, statefield) VALUES ('%s', '%s', '%s', '%s')",
                    mysql_real_escape_string($_POST['name']), // clean malicious code
                    mysql_real_escape_string($_POST['car']), // from user input
                    mysql_real_escape_string($_POST['color']), // to protect against
                    mysql_real_escape_string($_POST['state'])); // SQL injection
    
        // run the query
        $result = mysql_query($query);
    
        // check if the insert was done successfully
        if($result){
            echo 'SQL successfully updated.';
        }
    }
    

    If you notice, based on the id we used on the javascript object to assign the data, we are accessing it in the $_POST array. E.g.

    The name

    var myData = {
            name : 'Jeremy',
            ...
    }
    

    Will be access on PHP side with

    $_POST['name']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been chasing my tail on this! And it should be so simple!!
This is doing my head in, been chasing it all day. We have an
I have been chasing this bug around, and I just don't get it. Have
I ask this because I have been chasing down a co/contravariance issue in SL4.
I've been chasing my tail on this one. I have a single table (keeping
I've been chasing this one around for a couple of days and it's starting
How do I know if I am overanalysing? I've been chasing a problem the
I recently spent some time chasing an annoying little bug and I'm looking for
I have a bug I am chasing (I think its a deadlock). When I
I have a Windows.Forms application and I change the resources at runtime with 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.