How do I insert an array into the database properly?
HTML code:
Picture 1
Picture 2
Picture 3
PHP Code:
Picture 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--------------------
defined in the database:
SQL Code
Data varchar (+) NOT NULL
------Solution--------------------
PHP Code
foreach ($attachment as $v) mysql_query ("Insert ..."); Do not know your field, can only write this.
------Solution--------------------
The value of the array is taken out and stored in the library, separated by special characters, need to be taken out to deal with
------Solution--------------------
Compare support for 3 floor recommendations
------Solution--------------------
Storage time:
$date = "1.JGP/1.JGP";
By the time:
List ($one, $two) = Split (' [/.-] ', $date);
echo "one: $one; one: $two
\ n ";
------Solution--------------------
First, do you think you are a character array, or a numeric array, if you use a numeric array, with foreach ($attachment as $v)
、、
Second, is a character array, on the third floor, the characters are separated, and stored together into the database.
------Solution--------------------
All attachments should belong to a topic and do not need to be modified frequently, a field is done. Restore it when you need it.
PHP code
$arr =array (' 1.jpg ', ' 2.jpg ', ' 3.jpg '); $value = Serialize ($arr);
------Solution--------------------
Anyway, after you use Addslashes, no one knows what the user is submitting.
above the json_encode,serialize, after all to addslashes, avoid the quotation marks or the user malicious injection caused unnecessary trouble, out of the library time strip_slashes.
------Solution--------------------
Serialization
------Solution--------------------
Discussion
In any case, use addslashes after storage, no one knows what the user is committing.
above the json_encode,serialize, after all to addslashes, avoid the quotation marks or the user malicious injection caused unnecessary trouble, out of the library time strip_slashes.