I am trying to insert a string of given tags into a MySQL table, but it's not quite working out.
$tags = array explode (", ", $_POST["tags"]);
$tag_array = implode(", ", $tags);
My table has the columns tag_id(auto increment) and tag_name(where each item of array needs to go into)
How do I cycle through my array and make MySQL insert a blank value into tag_id (as it's auto incremented) and each of my array values into the tag_name column?
$mysqli->prepare("INSERT INTO tags VALUES (?)")
combined with foreach – Hiroto Jan 18 at 16:37apple, orange,banana, [three spaces] tomato, [6 spaces] etc.
. You can do this easily bytrim($tags)
and/ or just separating by comma (without the space) likeexplode(',', $_POST['tags']);
. – user1477388 Jan 18 at 16:38$tag_array
will be equal to$_POST["tags"]
afterwards. – lethal-guitar Jan 18 at 16:38