<?php
include "scrinit.php";
include $menu;
include "dbconnect.php";

	$mitr=$_POST['mitr'];
	$problima=$_POST['problima'];
	$stirixi=$_POST['stirixi'];
	$sxolio=$_POST['sxolio'];
	$aporos=$_POST['aporos'];
	$apal=$_POST['apallagi'];
	$peria=$_POST['perda'];
	$stir=$_POST['stiriksi'];
	$peris=$_POST['persa'];

	$dief1=$_POST['dief1'];
	$dief2=$_POST['dief2'];
	$dief3=$_POST['dief3'];
	$dief4=$_POST['dief4'];
	$dief5=$_POST['dief5'];
	$dief6=$_POST['dief6'];
	
	$sql=mysqli_query($con,"select mitroo from apallagesm where mitroo='$mitr'");
	if (mysqli_num_rows($sql)>0)
	{
		mysqli_query($con,"delete from apallagesm where mitroo='$mitr'");
       
	}
	$sql=mysqli_query($con,"select mitroo from stiriksim where mitroo='$mitr'");
	if (mysqli_num_rows($sql)>0)
	{
	
        mysqli_query($con,"delete from stiriksim where mitroo='$mitr'");
	
	}
	$sql=mysqli_query($con,"select mitroo from problimata where mitroo='$mitr'");
	if (mysqli_num_rows($sql)>0)
	{
	
		mysqli_query($con,"delete from problimata where mitroo='$mitr'");
	}
	$i=0;
	foreach($apal as $math)
	{
	   if ($math <>"")
	   {
	   $p=$peria[$i];
	   $sql1="insert into apallagesm (id,mitroo,mathima,per) values (NULL,'$mitr','$math','$p')";
	   if (mysqli_query($con, $sql1)) 
		{
    	 echo "New record created successfully";
		 } 
		 else 
		 {
    		echo "Error: " . $sql1 . "<br>" . mysqli_error($con);
    		}
	   }
	   $i++;
	}
	$i=0;
	foreach($stir as $math)
	{ 
	   if ($math <>"")
	   {
	   $p=$peris[$i];
	   $sql2="insert into stiriksim (id,mitroo,mathima,per) values (NULL,'$mitr','$math','$p')";
	   if (mysqli_query($con, $sql2)) 
		{
    	 echo "New record created successfully";
		 } else {
    		echo "Error: " . $sql2 . "<br>" . mysqli_error($con);
    		}
	   }
	   $i++;
	   
	}
	$sql="insert into problimata (mitroo,problima,sxolia,stiriksi,aporos,dief1,dief2,dief3,dief4,dief5,dief6) values
	            ('$mitr','$problima','$sxolio','$stirixi','$aporos','$dief1','$dief2','$dief3','$dief4','$dief5','$dief6')";
    if (mysqli_query($con, $sql)) 
	{
       echo "New record created successfully";
    } else {
    echo "Error: " . $sql . "<br>" . mysqli_error($con);
    }
    
?>
<br /><br />
<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού  </a>