<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
	<script src="/js/jquery-2.1.0.min.js"></script>
	<script src="/js/jquery.redirect.js"></script>
	<script type="text/javascript">   
function Redirect() 
{  
//	alert ('<?php print $_POST['DNUM']; ?>');

$.redirect('textecreamod.php', {'idxm': '<?php print $_POST['DNUM']; ?>'  });

	
} 
//document.write("You will be redirected to a new page in 5 seconds"); 
setTimeout('Redirect()', 500);   
</script>
	
	<style>
	
.attente{
	width:110px;
	height:110px;
	position:absolute;
	left:50%;
	top:50%;
	margin:-75px 0 0 -135px;
}
	</style>
	<img class="attente" src="spinner.gif">
    
	<?php 

	$debug=1;

 $myboxes = $_POST['DES'];
 $myboxes1 = $_POST['QTE'];  
 $myboxes2 = $_POST['PRIX']; 
 $myboxes3 = $_POST['UNITE'];  
 $myboxes4 = $_POST['ORDRELIGNE'];  
    $NumeroIndexDevis=$_POST['DNUM'];
    $NOMMOD=$_POST['NOM'];
    // update corps
	
	if(empty($myboxes))
	 
	{
	 
	// echo("You didn't select any boxes.");
  }
  else
  {
    $i = count($myboxes);
   // echo("<br>You have $i box(es): <br>");
    for($j = 0; $j < $i; $j++)
    {
      echo($myboxes[$j] . " ".$myboxes1[$j] ."  ".$myboxes2[$j] ." ".$myboxes3[$j] ."<br>");
    }
  }
    
    
	print "<div id='dnum'>numero type : ".$NumeroIndexDevis."</div>";
                                
	print $NumeroIndexDevis;
    print "<br>".$NOMMOD;
        
        
        
        		
$servername = "localhost:8889";
$username = "root";
$password = "root";
$dbname = "clients";

	// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
			 
	
	if(empty($myboxes))
	 
	{
	 
	// echo("You didn't select any boxes.");
  }
  else
  {
      
     $sql = " DELETE FROM `Modele` WHERE `type`='".$NumeroIndexDevis."' ";
     // print $sql;  print "<br>"; 
      $result = $conn->query($sql);
      
    $ic = count($myboxes);
	$ordl=0;
	$jc=0;
   // echo("You have $ic box(es): <br>");
    for($jc = 0; $jc < $ic; $jc++)
    {
		
		$myboxes[$jc]=str_replace("'","\'",$myboxes[$jc]);		
		$ordl++;
		//echo($myboxes[$j] . " ".$myboxes1[$j] ."  ".$myboxes2[$j] ." ".$myboxes3[$j] ."<br>");
		// $sql = "SELECT * FROM tete WHERE idx=1";
		//$sql = "UPDATE corps SET des='$myboxes[$j]', qt='$myboxes1[$j]', pu='$myboxes2[$j]', um='$myboxes3[$j]', numidxdevis='1'";
		$sql = "INSERT INTO `modele`(`description`, `prix`, `unite`, `type`,`nom`) VALUES ('$myboxes[$jc]','$myboxes2[$jc]','$myboxes3[$jc]','$NumeroIndexDevis','$NOMMOD')";
            //print $sql1."<br>";
		//$sql = "INSERT INTO corps des='$myboxes[$j]', qt='$myboxes1[$j]', pu='$myboxes2[$j]', um='$myboxes3[$j]', numidxdevis='1'";
		//echo "'<script type='text/javascript'>alert('enregistrement".$jc."')</script>";	 
		
if ($debug==1)   { print $sql;  print "<br>"; } 
$result = $conn->query($sql);
		 
		
    }
		
    }


		?>

	
	

<body>
</body>
</html>