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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:03:13+00:00 2026-06-11T08:03:13+00:00

I have a JSON array that is on a page. It is added to

  • 0

I have a JSON array that is on a page. It is added to as time goes on by some user interaction. When the user is done they need to submit this array to a page where their information is added to a mySQL table via php. My call to the page via AJAX is as follows where answersArray is the array

$.ajax({
    type: "POST",
    dataType: "json",
    data: answersArray,
    url: 'sendToUsersFeedback.php',
});

The array looks like this:

[
    {
        "USERID": "3",
        "INDVID": "0",
        "RATING": "1",
        "CONFIDENCE": "8"
    },
    {
        "USERID": "3",
        "INDVID": "1",
        "RATING": "1",
        "CONFIDENCE": "88"
    }
]

This is where I get confused. I need to decode this incoming json and then loop through it added a new record for each array item (USERID, INDVID, RATING and CONFIDENCE make up one record etc..) I could have as many as 20 in this array. I know USERID is not unique. Already have that set up.

It is the php side I get messed up on. How do I decode an incoming array and go through it. I have tried the following

$sql = json_decode(data,true);
foreach( $data as $row ) {
    $sql[] = '("'.mysql_real_escape_string($row['USERID']).'", '.$row['INDVID'].','.$row['RATING'].','.$row['CONFIDENCE'].')';
}
mysql_query('INSERT INTO users_feedback (USERID, INDVID, RATING. CONFIDENCE) VALUES '.implode(',', $sql));

Am I close? I’m very confused. Thanks in advance.

  • 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-11T08:03:15+00:00Added an answer on June 11, 2026 at 8:03 am

    First, give a name to your data you’re posting :

    $.ajax({
        type: "POST",
        dataType: "json",
        data: {
          my_data: answersArray
        },
        url: 'sendToUsersFeedback.php',
    });
    

    Then, in your PHP code, recover your data :

    $data = $_POST['my_data'];
    $sql = json_decode($data, true);
    ...
    

    You should be aware that everybody can edit JSON in the client-side, so insert data into a database this way is extremely dangerous.

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

Sidebar

Related Questions

I have a PHP file that returns a JSON array. I need to extract
I have some PHP script that logs in and returns a JSON array with
I have a PHP function that builds a JSON array via $jsonArray= array(); for
I have a PHP file that serves up a JSON array populated from a
I have a json object that looks something like this: Array ( [algorithm] =>
I have a php file somejson.php that echos a json encoded array {jsonone:first json,jsontwo:second
I have a function that returns json (networks_function.php builds up some arrays and encodes
I have a page that is posting a JSON to a cfc, and getting
I have a javascript rich page that is passing a large JSON formatted to
I need help here in my practice program. I have a json array: myData=[{plank_number:1,thickness:5,width:7,length_t:8,quantity:1},

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.