is it possible to implode a checkbox value into multiple values to insert into a database?
At current I have this:
$tags = implode(', ', $_POST['checkboxname']);
This gives me the value of "testtag1, testtag2"
How would I split this up so it would go into the database like:
Blog ID ¦ Tag
------------------
1 ¦ testtag1
1 ¦ testtag2
Not sure how to make the implode function seperate them as this:
$query2 = mysqli_query($myConnection, "INSERT INTO blogtags (blogid, tag) VALUES('$blogid','$tags')") or die (mysqli_error($myConnection));
just inserts the two values together in one row.
Any help would be great! Thanks
Try this example:
$tags = $_POST['checkboxname'] ; //Take the array of tags.
$id = 1 ; //Set needed id.
$values = array() ;
foreach($tags as $tag){
$tag = $myConnection->real_escape_string($tag);
$values[] = " ('{$id}', '{$tag}') " ;
}
$values = implode(" , ", $values) ;
$query = "INSERT INTO blogtags (blogid, tag) VALUES {$values} ; " ;