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

//check for required fields
if (isset($_POST['MessageID']) && 
		isset($_POST['ReceiverID']) && 
		isset($_POST['ReceiverMobileNo']) &&   
		isset($_POST['ReceiveTime']) &&   
		isset($_POST['ReadTime']) &&
		isset($_POST['SenderMobieNo']) &&   
		isset($_POST['NetCode']) &&                                           
		isset($_POST['SysCode']) &&                                                                                      
		isset($_POST['ReceiverStatus'])) {

		$MessageID= $_POST['MessageID']; 
		$ReceiverID= $_POST['ReceiverID']; 
		$ReceiverMobileNo= $_POST['ReceiverMobileNo']; 
		$ReceiveTime= $_POST['ReceiveTime'];   
		$ReadTime= $_POST['ReadTime'];   
		$SenderMobieNo= $_POST['SenderMobieNo'];
		$NetCode= $_POST['NetCode'];                                           
		$SysCode= $_POST['SysCode'];        
		$ReceiverStatus= $_POST['ReceiverStatus']; 

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

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

          $sql = "UPDATE Chat2Receiver SET MessageID = '$MessageID', ReceiverID = '$ReceiverID', ReceiverMobileNo = '$ReceiverMobileNo',ReceiveTime = '$ReceiveTime', ReadTime = '$ReadTime', SenderMobieNo = '$SenderMobieNo', NetCode = '$NetCode',
          SysCode = '$SysCode', UpdatedDate = '$UpdatedDate' ,ReceiverStatus='$ReceiverStatus' WHERE ReceiverID = $ReceiverID";
          $params = array();
		 
		try{	
			$stmt = $conn->prepare($sql);
			$stmt->execute();
			$result= $stmt->rowCount();
		}
		catch(PDOException $e){
			echo $sql . "<br>" . $e->getMessage();
		}
		if ( $result=== TRUE) {
				$rows_affected= "No information available.";
				$response["success"] = 1;
				$response["roweffected"] = $rows_affected;
				$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);
    }
?>
