php - using foreach loop for multiple MySQL inserts -


i'm using following snippet break string array, insert them database.

//split tags individual words         $tag_array = explode(',', $tags);          foreach($tag_array $tag){             addslashes($tag);             echo $tag."&nbsp;";             $addtagsquery = "insert `my_blog`.`tags` (`id`, `name`) values              ('".$id."', '".$tag."');";             $tagsresult = $db->query($addtagsquery);             if($tagsresult){                 echo "tag added <br />";             }             else {                 echo "tag not added <br />";             }          } 

my problem lies within scenario multiple tag (strings) submitted. unfortunately, first string in array inserted. insight why first string in array inserted mysql database appreciated.

$id not being incremented in loop. chances getting duplicate error, whatever reason not telling (poor error handling?).

$addtagsquery = "insert `my_blog`.`tags` (`name`) values              ('".$tag."');";

if id auto_incrementing, omit , handle you.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -