<?php
	die('Invalid URL');
	$records_inserted = 0;
	$tag_query = "SELECT * FROM keycode WHERE name = 'tags' ";
	$tag_sql1 = mysqli_query($conn,$tag_query);
	if(mysqli_num_rows($tag_sql1)){
		while($row = mysqli_fetch_array($tag_sql1)){
			$id 			= $row['id'];
			
			$code_array = explode(",",$row['code']);
			$code_name = "";
			foreach($code_array as $key=>$value){
				//echo $value.'<br>';
				$code_name .= $value.",";
				
			$records_inserted++;
			
			if(isset($value) && $value !=""){
				$value_id = utility::getTableFieldById("tags","id","tag",$value);
				if(!(isset($value_id) && $value_id !="")){
					mysqli_query($conn,"INSERT INTO tags(tag,updated_by,created_on,created_by) VALUE('$value','".$_SESSION['user_id']."','".date('Y-m-d H:i:s')."','".$_SESSION['user_id']."')");
					//$value_id = mysqli_insert_id();
				}
			}else{
		
				$sql= "INSERT INTO tags (tag,updated_by,created_on,created_by) VALUES('$value','".$_SESSION['user_id']."','".date('Y-m-d H:i:s')."','".$_SESSION['user_id']."')";
				mysqli_query($conn,$sql);
				}
			}
		}
	}

?>
<?php 
if($records_inserted){    
  echo '<br><span style="font-family:calibri;color:red;">'.($records_inserted).' records has been inserted...</span>';
}?>
