<?php
include ("config.php");

$selectuser = $_SESSION['s_username'];
$countItems = $_POST["totalRows"];
$partArray = array();
$qtyArray = array();

//GO THROUGH THE CHECKBOXES THAT ARE CHECKED...
	$i = 0; //start a counter
	//It is necessary to turn the $_POST map into a number valued array
	foreach ($_POST as $key => $value)
		{
			if(substr($key,0,5) == "check")  //TAKE OUT THE Checked FIELD VALUE
			{
				if (in_array($value,$partArray))
				continue;
				else
				$partArray[$i] = $value; //after check
			}
			else if(substr($key,0,3) == "qty")  //TAKE OUT THE QTY FIELD VALUE
			{
				if (in_array(substr($key,3),$partArray))
					{
						$qtyArray[$i] = $value;
						$i++;
					}
				else continue;
			}
		}
	
// Database connection variables 
$dbServer = $mysqlserver; 
$dbDatabase = $mysqldatabase; 
$dbDatabase2 = $mysqldatabase2; 
$dbUser = $mysqlusername; 
$dbPass = $mysqlpassword;

$sConn = mysql_connect($dbServer, $dbUser, $dbPass) 
or die("Couldn't connect to database server"); 
$dConn = mysql_select_db($dbDatabase, $sConn) 
or die("Couldn't connect to database $dbDatabase");

	$i = 0; //Start the counter 
    //$j = 0;
	//echo "Number of records: " . count($partArray) . "<br>";
	
	while ($i < (count($partArray))) //Loop for the entire size of the array
	{
			$SKU = ($partArray[$i]);
			//$i++;
			$qty = ($qtyArray[$i]);
			$i++;
        //echo " SKU: " . $SKU . " ";
        //echo " qty: " . $qty . "<br>";
		
		if ($SKU == "")
		continue 1;
		else
		{
		  $queryCheck = "UPDATE `hiresolution` SET `checked` = '1' WHERE `SKU` = '" . $SKU . "' LIMIT 1;";
		  //echo $queryCheck . "<br>";
		  $skuResultCheck = mysql_query($queryCheck);
		 }	
	}
	
	header('Location: http://www.overstockart.net/sorter/hi-res-sku-list-checked.php');
?>