[PHP, MySQL] foreach loop only submitting last element of array

I’m trying to create a tagging system that parses a comma delimited string into separate records for a database, using PHP, MySQL, and Dreamweaver. I’ve built a form that does this using PHP’s explode function and a foreach loop. It’s sort of working, without errors, but there’s a bug that I can’t quite figure out.

When I submit the form, everything appears to work normal, but when I check the table in my DBMS (phpMyAdmin), the only tag that gets submitted is the last one in the comma delimited list, that is, the last element in the array that explode(); creates. Any help at all would be great. Here’s the code in question:


if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
//parse the string of tags (tag_string) into the array $tags
$tags = explode(",",$_POST['tag_string'], 8);
foreach($tags as $tag) {
  $insertSQL = sprintf("INSERT INTO tags (object_id, tag) VALUES (%s, %s)",
                       GetSQLValueString($_POST['object_id'], "int"),
                       GetSQLValueString($tag, "text"));
                       }