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

//check for required fields
if ( isset($_POST['PotionID']) && isset($_POST['TableID']) 
	&& isset($_POST['TableDescription'])&& isset($_POST['TableStatus'])
	&& isset($_POST['UpdatedDate']) 
	&& isset($_POST['ClientID']) && isset($_POST['ClientUserID']) 
	&& isset($_POST['NetCode']) && isset($_POST['SysCode'])&& isset($_POST['SalPur1ID']) ){
		
		$TableID = $_POST['TableID'];
  		$PotionID = $_POST['PotionID'];
		$TableDescription = $_POST['TableDescription'];
  		$TableStatus = $_POST['TableStatus'];
  		$ClientID = $_POST['ClientID'];
  		$ClientUserID = $_POST['ClientUserID'];
  		$NetCode = $_POST['NetCode'];
  		$SysCode = $_POST['SysCode'];
		$UpdatedDate = $_POST['UpdatedDate'];
	$SalPur1ID = $_POST['SalPur1ID'];
      // include db connect class
      require_once __DIR__ . '/../DBConnect.php';

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

          $sql = "UPDATE Restaurant2Table SET TableID = '$TableID', PotionID = '$PotionID', TableDescription = '$TableDescription',TableStatus = '$TableStatus', SalPur1ID = '$SalPur1ID',ClientID = '$ClientID', ClientUserID = '$ClientUserID', NetCode = '$NetCode',
          SysCode = '$SysCode', UpdatedDate = '$UpdatedDate'  WHERE TableID = '$TableID' 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);
    }
?>
