<?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];
	   mysqli_query($con,"insert into apallagesm (id,mitroo,mathima,per) values (NULL,'$mitr','$math','$p')");
	   }
	   $i++;
	}
	$i=0;
	foreach($stir as $math)
	{ 
	   if ($math <>"")
	   {
	   $p=$peris[$i];
	   mysqli_query($con,"insert into stiriksim (id,mitroo,mathima,per) values (NULL,'$mitr','$math','$p')");
	   $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>