<?php
include("connection.php");
?>
<html>
<body bgcolor="#871F1F" text="#FFFFFF" link="#000000" vlink="#000000" alink="#000000">
<title>ANISEED</title>
<center>
<?php
	
	$comp=$_POST["comp"];
	$cell= $_POST["region"];

	
	
	
	if( (count($comp)<=0)or(strlen($cell)<=0) ){
	    print "Error: missing parameter";
		return;
	}else{


	    
		for($m=0;$m<count($comp);++$m){
		    $fate=$comp[$m];
		
			$requete="select * from \"COMPETENCE\" where (\"CELL\"=$cell) and (\"COMPETENCE\"='$fate')";
			$stmt2 = pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));
			if(! $row2=pg_fetch_array($stmt2)){
				pg_query($c,"begin");
				$requete="insert into \"COMPETENCE\" (\"CELL\", \"COMPETENCE\") values($cell, '$fate')";
				$stmt3 = pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));
				pg_query($c,"commit");
				
			}else{
			    print 'Error: one of these data already exists in the database<br>';
			}
		
		}
		print "Data successfully entered";
		
		
		
	}
?>
<br><br><br>
<input type="button" name="OK" onClick="javascript: self.close();" value=" OK ">
</center>
</body>
</html>