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

//check for required fields
if ( isset($_POST['ClientID']) ) {
		
		$PotionID = $_POST['PotionID'];
  		$PotionName = $_POST['PotionName'];
		$PotionDescriptions = $_POST['PotionDescriptions'];
  		$ClientID = $_POST['ClientID'];
  		$ClientUserID = $_POST['ClientUserID'];
  		$NetCode = $_POST['NetCode'];
  		$SysCode = $_POST['SysCode'];
		$UpdatedDate = $_POST['UpdatedDate'];
      // include db connect class
      require_once __DIR__ . '/../DBConnect.php';
               $parm=array();
	           $query="select max(PotionID) as maxid from Restaurant1Potion where ClientID =".$ClientID;
	        
			  
				try {
						$stmt = $conn->prepare($query);
						$stmt->execute();
						$users = $stmt->fetchAll();
						$PotionID = 0;
						foreach ($users as $user) {
							$PotionID = $user['maxid'] + 1;
						}
					}
					catch (PDOException $e) {
						echo $sql . "<br>" . $e->getMessage();
					}
	                  
			    $UpdatedDate = date("Y-m-d H:i:s");
				$sql = "INSERT INTO Restaurant1Potion (PotionID, PotionName, PotionDescriptions, ClientID, ClientUserID, UpdatedDate, NetCode, SysCode) VALUES('$PotionID', '$PotionName', '$PotionDescriptions', '$ClientID', '$ClientUserID', '$UpdatedDate', '$NetCode', '$SysCode');";
      		
      		try {
			$result= $conn->exec($sql);		   
			if( $result === false ) {
			/////////////not inserted
				$response["success"] = 0;  
				$response["message"] = "User Not Register";
			echo json_encode($response);
			}else{
				/////////////inserted
			$response["success"] = 1;
            $response["PotionID"] = $PotionID;
            $response["UpdatedDate"] = $UpdatedDate;
            $response["message"] = "User Register";
			echo json_encode($response);
			}
			
		}catch (PDOException $e) {
						echo $sql . "<br>" . $e->getMessage();
					}
		 
    }else{
      // success
      $response["success"] = 0;
      $response["message"] = "Send All Required Fields ";
      // echoing JSON response
      echo json_encode($response);
    }
?>
