How to insert an array to the database? Html code: & lt; inputtype & quot; checkbox & quot; name & quot; attachment [] & quot; value & quot; 1.jgp& quot; & gt; image 1 & lt; inputtype & quot; checkbox & quot; name & quot; attachment how to insert an array into the database?
Html code:
Image 1
Image 2
Image 3
Php code:
// Image attachment area
$ Attachment = $ this-> var ['GP _ attachment '];
Foreach ($ attachment as $ value ){
P ($ value );
// Save the value to the database
}
Array format
Array
(
[0] => 1.jgp
[1] => 2.jpg
)
Php: 5.3.10
------ Solution --------------------
Define in the database:
SQL code
Data varchar (100) not null
------ Solution --------------------
PHP code
Foreach ($ attachment as $ v) mysql_query ("insert..."); // You do not know your field. you can only write it like this.
------ Solution --------------------
Extract the value of the array to the database and separate it with special characters. if necessary, extract it before processing.
------ Solution --------------------
Suggestions for supporting the third floor
------ Solution --------------------
Storage:
$ Date = "1.jgp/ 1.jgp ";
Time to use:
List ($ one, $ two) = split ('[/.-]', $ date );
Echo "one: $ one; two: $ two
\ N ";
------ Solution --------------------
First, do you think you are a character array or a number array? if you use a number array, use foreach ($ attachment as $ v)
,,
The second is the character array, which is separated by characters on the third floor and stored in the database together.
------ Solution --------------------
All attachments should belong to one topic and do not need to be modified frequently. you can use one field to restore it if necessary.
PHP code
$Arr=array('1.jpg ', '2.jpg', '3.jpg'); $ value = serialize ($ arr );
------ Solution --------------------
In any case, use addslashes to import data to the database. no one knows what the user submits.
The preceding json_encode and serialize must be followed by addslashes to avoid quotation marks or unnecessary troubles caused by malicious injection. strip_slashes is used for outbound delivery.
------ Solution --------------------
Serialization
------ Solution --------------------
Discussion
In any case, use addslashes to import data to the database. no one knows what the user submits.
The preceding json_encode and serialize must be followed by addslashes to avoid quotation marks or unnecessary troubles caused by malicious injection. strip_slashes is used for outbound delivery.