PHP: Duplicate/Blank values when Inserting image names into the DB
I am currently storing in MySQL database image names for easier way to retrieve the actual images. I am having problems with  the php code I created that stores the names. Duplicate and blank insertions are being made into the DB without my permission. 


Is there a way to avoid this issue of duplicate or blank values being inserted when the page refreshed?

![enter image description here][1]



    <?
        $images = explode(',', $_GET['i']);
        
        $path = Configuration::getUploadUrlPath('medium', 'target');
        
        
        if(is_array($images)){
        
        
        	try {
        		$objDb = new PDO("mysql:host=" . $host . ";dbname=" . $db, $user, $pass);
        		$objDb->exec('SET CHARACTER SET utf8');
        		
        		} catch(PDOException $e) {
        			echo 'There was a problem';
        		}
        		
        	$sql = "INSERT INTO `urlImage` (`image_name`) VALUES ";
        	
          foreach ($images as $image) {
        
            $value[] = "('".$image."')"; // collect imagenames
          }
        
          
          
           
        	$sql .= implode(',', $value).";"; //build query
        	$objDb->query($sql); 
        	//echo "<pre>"; print_r($sql);echo "</pre>";
        }
    
    ?>


  [1]: http://i.stack.imgur.com/8Trdq.jpg
PHP: Duplicate/Blank values when Inserting image names into the DB
===

I am currently storing in MySQL database image names for easier way to retrieve the actual images. I am having problems with  the php code I created that stores the names. Duplicate and blank insertions are being made into the DB without my permission. 


Is there a way to avoid this issue of duplicate or blank values being inserted when the page refreshed?

![enter image description here][1]



    <?
        $images = explode(',', $_GET['i']);
        
        $path = Configuration::getUploadUrlPath('medium', 'target');
        
        
        if(is_array($images)){
        
        
        	try {
        		$objDb = new PDO("mysql:host=" . $host . ";dbname=" . $db, $user, $pass);
        		$objDb->exec('SET CHARACTER SET utf8');
        		
        		} catch(PDOException $e) {
        			echo 'There was a problem';
        		}
        		
        	$sql = "INSERT INTO `urlImage` (`image_name`) VALUES ";
        	
          foreach ($images as $image) {
        
            $value[] = "('".$image."')"; // collect imagenames
          }
        
          
          
           
        	$sql .= implode(',', $value).";"; //build query
        	$objDb->query($sql); 
        	//echo "<pre>"; print_r($sql);echo "</pre>";
        }
    
    ?>


  [1]: http://i.stack.imgur.com/8Trdq.jpg