Your foreach line has the potential to break something: $tag and $tag is being used to mean two different things at the same time.
PHP Code:
foreach( $tag as $key => $value ) { $tag [ $key ] = "'" . mysql_real_escape_string ( $value ). "'" ; } $query = "Select tag_name from tags where tag_name in (" . join ( ',' , $tags ). ")"...



