I’m trying to insert an array into a mysql database
heres my array
[amenities] => Array
(
[0] => 1
)
So I’ll use the implode() to convert the array into a comma seperated string
$amenities = implode(",",$_POST['amenities[]']);
but when I echo that variable, I get nothing.
Is that right?
Typo:
$amenities = implode(",",$_POST['amenities']);
oh, got it, just had to remove the from the POST variable.
Yep. Keep in mind although you may put in your form name (so it is designated as an array), the post accessor for that element does not contain those characters. You simply reference it by its name without the
If you find yourself needing to store an array in a database its advisable to use a child table so that the data stored therein can be searched.
If it needs to be searched. No sense in decoupling data that would never be searched on (ie: preference settings).