Submit an array in phppost mode

Source: Internet
Author: User
In phppost mode, if you want to submit an array (1 => '1', 2 => '1',) to the v2 field of the table in the test Database, how should we write it?


Reply to discussion (solution)

First? And then json_encode in?

$ Arr = array (1 => '1', 2 => '1 ');
$ V2 = json_encode ($ arr );

$ SQL = "insert into table (v2) values ('". $ v2 ."')";

First? And then json_encode in?

$ Arr = array (1 => '1', 2 => '1 ');
$ V2 = json_encode ($ arr );

$ SQL = "insert into table (v2) values ('". $ v2 ."')";


Sorry, I may not be very clear about it,

For example:


1. php
$ V2 = $ _ POST ['V2'];

Print_r ($ v2); you can get Array ([0] => 1 [1] => 2). when submitting data to the database, only Array is available, I want to submit the entire Array ([0] => 1 [1] => 2) to the field.

First? And then json_encode in?

$ Arr = array (1 => '1', 2 => '1 ');
$ V2 = json_encode ($ arr );

$ SQL = "insert into table (v2) values ('". $ v2 ."')";


As mentioned above, I will reference $ v2 = json_encode ($ _ POST ['V2']) and add $ v2 to the database.

Json_encode: decode it when it is obtained ..
Why store data such as 'array ([0] => 1 [1] => 2) 'in the field.


First? And then json_encode in?

$ Arr = array (1 => '1', 2 => '1 ');
$ V2 = json_encode ($ arr );

$ SQL = "insert into table (v2) values ('". $ v2 ."')";


As mentioned above, I will reference $ v2 = json_encode ($ _ POST ['V2']) and add $ v2 to the database.


$ V2 = json_encode ($ _ POST ['V2']); submit it to the database to get ["1", "2"]. I want to submit it to get Array (1 => 1 ,) this way

Json_encode: decode it when it is obtained ..
Why store data such as 'array ([0] => 1 [1] => 2) 'in the field.



The reading format of a cms is like this.


Json_encode: decode it when it is obtained ..
Why store data such as 'array ([0] => 1 [1] => 2) 'in the field.



The reading format of a cms is like this.



Just convert it into an array when reading it.



Json_encode: decode it when it is obtained ..
Why store data such as 'array ([0] => 1 [1] => 2) 'in the field.



The reading format of a cms is like this.



Just convert it into an array when reading it.


Little Cainiao is studying hard. I don't know much about it in many places !! Ask for advice ..

Because? The db field stores a string. if you are ???? Go ,?? ?? Character Array .?? ?? Loss.
For example:
$ Arr = array (1, 2, 4 );
Echo $ arr; // Array

So json_encode first ?? String ,? ? Then json_decode ????.

Because? The db field stores a string. if you are ???? Go ,?? ?? Character Array .?? ?? Loss.
For example:
$ Arr = array (1, 2, 4 );
Echo $ arr; // Array

So json_encode first ?? String ,? ? Then json_decode ????.


Thank you, moderator.

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.