<?php
session_start();
//$connect = new mysqli("localhost", "sooggoo", "4Compassion*", "evergreenint"); 

           
    // Initialize 'thirdColumnData' as an empty array if it doesn't exist
 if (!isset($_SESSION['lponodata'])) {
    $_SESSION['lponodata'] = array();
}  
//suppinvnodata
 if (!isset($_SESSION['suppinvnodata'])) {
    $_SESSION['suppinvnodata'] = array();
} 


if (isset($_POST['lpono']) && isset($_POST['suppinvnodata']) && isset($_POST['action'])) {
	// Check if the checkbox is checked or unchecked
    if ($_POST['action'] == 'add') {
        // Add the age data to the session array
       
        // Add the age value if not already in the session
        if (!in_array($_POST['lpono'], $_SESSION['lponodata'])) {
      $_SESSION['lponodata'][] = $_POST['lpono'];
		//array_push($_SESSION['lpono'], $_POST['lpono']);
			 //$_SESSION['lpono'] = array_merge($_SESSION['lpono'], array($_POST['lpono']));
			 //$_SESSION['thirdColumnData'][] = $columnData;
        }

		 if (!in_array($_POST['suppinvnodata'], $_SESSION['suppinvnodata'])) {
      $_SESSION['suppinvnodata'][] = $_POST['suppinvnodata'];
		//array_push($_SESSION['lpono'], $_POST['lpono']);
			 //$_SESSION['lpono'] = array_merge($_SESSION['lpono'], array($_POST['lpono']));
			 //$_SESSION['thirdColumnData'][] = $columnData;
        }
        
		
    } elseif ($_POST['action'] == 'remove') {
        // Remove the age data from the session
        if (isset($_SESSION['lponodata']) && ($key = array_search($_POST['lpono'], $_SESSION['lponodata'])) !== false) {
            unset($_SESSION['lponodata'][$key]); // Remove the data from the array
			
			
			 // Reindex the array to maintain numeric keys
            $_SESSION['lponodata'] = array_values($_SESSION['lponodata']);
        }

         if (isset($_SESSION['suppinvnodata']) && ($key = array_search($_POST['suppinvnodata'], $_SESSION['suppinvnodata'])) !== false) {
            unset($_SESSION['suppinvnodata'][$key]); // Remove the data from the array
			
			
			 // Reindex the array to maintain numeric keys
            $_SESSION['suppinvnodata'] = array_values($_SESSION['suppinvnodata']);
        }
    
		
    }
	$connect = new mysqli("localhost", "sooggoo", "4Compassion*", "evergreenint"); 
	$sql = "DROP TABLE IF EXISTS supptemp";
				$result = mysqli_query($connect,$sql);
		

		
		$sql = "CREATE TABLE supptemp (" . " lpono VARCHAR(100) NOT NULL," . " suppinv VARCHAR(100) NOT NULL)";
				$result =  mysqli_query($connect,$sql);
	

	$lponos = implode(", ", $_SESSION['lponodata']);
	 $inv=implode(", ", $_SESSION['suppinvnodata']);
	//$lponos = mysqli_real_escape_string($mysqli, $lponos);
	//$inv = mysqli_real_escape_string($mysqli,  $inv);
	
$inserttemp2 = "
    INSERT INTO supptemp
      ( lpono,suppinv)
	  VALUES ( 
							'" . $lponos."',
							'" . $inv."'
						)";
   

			$result3 =  mysqli_query($connect,$inserttemp2);
		
	
		
}




?>
