<?php
// array for JSON response
$response = array();

//check for required fields
if ( isset($_POST['Item2GroupID']) &&
isset($_POST['Item3NameID']) &&
isset($_POST['ItemName']) &&                                           
isset($_POST['ClientID']) &&    
isset($_POST['ClientUserID']) && 
isset($_POST['NetCode']) &&   
isset($_POST['SysCode']) &&                                              
isset($_POST['SalePrice']) &&                               
isset($_POST['ItemCode']) &&                                           
isset($_POST['Stock']) &&
isset($_POST['WebUrl']) &&
isset($_POST['MinimumStock']) &&
isset($_POST['ItemDescription'])



) {

 $Item3NameID = $_POST['Item3NameID'];
         $Item2GroupID = $_POST['Item2GroupID'];
	$ItemName = $_POST['ItemName'];
  		$ClientID = $_POST['ClientID'];
  		$ClientUserID = $_POST['ClientUserID'];
  		$NetCode = $_POST['NetCode'];
		  $SysCode = $_POST['SysCode'];
		  	$SalePrice = $_POST['SalePrice'];
  		$ItemCode = $_POST['ItemCode'];
  		$Stock = $_POST['Stock'];
  		$WebUrl = $_POST['$WebUrl'];
  		$MinimumStock = $_POST['$MinimumStock'];
  		$ItemDescription = $_POST['$ItemDescription'];


      // include db connect class
       require_once __DIR__ . '/../DBConnect.php';

			    $UpdatedDate = date("Y-m-d H:i:s");

          $sql = "UPDATE Item3Name SET Item2GroupID = $Item2GroupID,
                  ItemName = '$ItemName',
                  ClientUserID = $ClientUserID, 
                  SysCode = '$SysCode',
                  UpdatedDate = '$UpdatedDate', 
                  NetCode = '$NetCode' ,
                  SalePrice = $SalePrice,
                  ItemCode = '$ItemCode',
                  Stock = $Stock ,
                  WebUrl = $WebUrl,
                  MinimumStock = $MinimumStock,
                  ItemDescription = $ItemDescription
                  WHERE Item3NameID = $Item3NameID AND ClientID=".$ClientID;
          $params = array();
      	 $result=0;
		try{	
			$stmt = $conn->prepare($sql);
			$stmt->execute();
			$result= $stmt->rowCount();
		}
		catch(PDOException $e){
			echo $sql . "<br>" . $e->getMessage();
		}
		if ( $result!= 0) {
				$rows_affected= "No information available.";
				$response["success"] = 1;
				$response["roweffected"] = $result;
				$response["UpdatedDate"] = $UpdatedDate;
				$response["message"] = "Update Successfully";
				// echoing JSON response
				echo json_encode($response);
		}else{
				$response["success"] = 0;
				$response["roweffected"] = $result;      
				$response["message"] = "Not updated row ".$result;
				// echoing JSON response
				echo json_encode($response);
		}
    }else{
      // success
      $response["success"] = 0;
      $response["message"] = "No Update";
      // echoing JSON response
      echo json_encode($response);
    }
?>
