How to transfer JSON arrays to PHP via AJAX and insert data into the database via PHP

Source: Internet
Author: User
Title. I just started to learn PHP, the foundation is not good, Baidu for a long time can not be achieved, hoping to give examples. The JSON data is stitched together to get
T

1.php does not write


Reply to discussion (solution)

The format returned by the general Web site is a JSON post submission that is written as "Shop=%e5%95%86%e5%ba%971&goods=%e8%b4%a7%e7%89%a91& ..." (URL encoding)

php to get $shop = $_post[' shop '];
inserting into a database

First of all, your fields were wrongly written.
It is unlikely to use JS code to assemble JSON strings, or at least to use the Ajax.stringify method to convert
To write (the clear point of a break)

var fields = [  {"Shop": "Store 1", "goods\": "Goods 1", "Price": "10 Yuan"},  {"Shop": "Store 2", "goods": "Goods 2", "Price": "11 Yuan"},< c2/>{"Shop": "Store 3", "goods": "Goods 3", "Price": "13 Yuan"}];

Upon submission
Data: {Fields:fields},


PHP side $_post[' Fields ' is an array of commits

The format returned by the general Web site is a JSON post submission that is written as "Shop=%e5%95%86%e5%ba%971&goods=%e8%b4%a7%e7%89%a91& ..." (URL encoding)

php to get $shop = $_post[' shop '];
inserting into a database


JSON array is to get the data of table splicing, no id,name and so do not know how to form this URL encoding

First of all, your fields were wrongly written.
It is unlikely to use JS code to assemble JSON strings, or at least to use the Ajax.stringify method to convert
To write (the clear point of a break)

var fields = [  {"Shop": "Store 1", "goods\": "Goods 1", "Price": "10 Yuan"},  {"Shop": "Store 2", "goods": "Goods 2", "Price": "11 Yuan"},< c2/>{"Shop": "Store 3", "goods": "Goods 3", "Price": "13 Yuan"}];

Upon submission
Data: {Fields:fields},


PHP side $_post[' Fields ' is an array of commits


How does PHP write, how to insert the received JSON array into the database?
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.