拆分字符串并将每个值输入mysql

I have tags in the form of tag1,tag2,tag3 that I want to enter into the a table i.e

tag_id    tag_name    topic_id
  1         php          1
  2         ajax         2
  3         mysql        3
  4         html         4

The script below doesn't do that. I dont get any error on the screen

$topic_tag = explode("," , $topic_tags) ;

       foreach($topic_tag as $topic_tags) {
       $query = "INSERT INTO `forum_tags` (`tag_id`, `tag_name`) 
       VALUES ( NULL, '" .mysql_real_escape_string(trim($topic_tags))."')";
       } 

Consider using PDO for your SQL requests : http://php.net/manual/en/book.pdo.php

For example :

$statement = $pdo_object->prepare('INSERT INTO `forum_tags` (`tag_id`, `tag_name`, `topic_id` ) VALUES ( ?, ?, ?) ');
$statement->execute( $topic_tags );