<?php
// array for JSON response
$response = array();
require_once __DIR__ . '/../DBConnect.php';

//check for required fields

if(isset($_POST['AcName'])&& isset($_POST['CountryClientID']) && isset($_POST['NewPassword']) && isset($_POST['UpdatedName'])){
    
    	 
    	    	$AcName  =     $_POST['AcName'];
  		        $ClientId  =   $_POST['CountryClientID'];
  		        $UpdatedName =$_POST['UpdatedName'];
  		        $NewPassword=$_POST['NewPassword'];
  		
    	 
    	   	$sql = "UPDATE Account3Name SET NameOfPerson='$UpdatedName', AcPassward='$NewPassword' WHERE AcName= $AcName AND ClientID = $ClientId";
       	      
       	
       		$result=0;
				try{	
					$stmt = $conn->prepare($sql);
					$stmt->execute();
					$result= $stmt->rowCount();
				}
				catch(PDOException $e){
					echo $sql . "<br>" . $e->getMessage();
				}
				if ( $result!= 0) {
						
						$response["success"] = 1;
						$response["roweffected"] = $result;
					
				     	$response["message"] = "Update Successfully";
						// echoing JSON response
						echo json_encode($response);
				}else{
						$response["success"] = 0;
						$response["roweffected"] = $result;      
						$response["message"] = "Not updated row ";
						// echoing JSON response
						echo json_encode($response);
				}              
    
}
else if (isset($_POST['AcName'])&& isset($_POST['CountryClientID']) && isset($_POST['UpdatedName'])) {

     
  		$AcName  =     $_POST['AcName'];
  		$ClientId  =   $_POST['CountryClientID'];
  		$UpdatedName =$_POST['UpdatedName'];
  		
  	   
       
     
       	$sql = "UPDATE Account3Name SET NameOfPerson='$UpdatedName' WHERE AcName= $AcName  AND ClientID = $ClientId";
       	      
       	
       		$result=0;
				try{	
					$stmt = $conn->prepare($sql);
					$stmt->execute();
					$result= $stmt->rowCount();
				}
				catch(PDOException $e){
					echo $sql . "<br>" . $e->getMessage();
				}
				if ( $result!= 0) {
						
						$response["success"] = 1;
						$response["roweffected"] = $result;
					
				     	$response["message"] = "Update Successfully";
						// echoing JSON response
						echo json_encode($response);
				}else{
						$response["success"] = 0;
						$response["roweffected"] = $result;      
						$response["message"] = "Not updated row ";
						// echoing JSON response
						echo json_encode($response);
				}

		
	
}else if(isset($_POST['AcName'])&& isset($_POST['CountryClientID']) && isset($_POST['NewPassword'])){
    
    	 
    	    	$AcName  = $_POST['AcName'];
  		        $ClientId  = $_POST['CountryClientID'];
  		        $NewPassword=$_POST['NewPassword'];
    	 
    	   	$sql = "UPDATE Account3Name SET AcPassward='$NewPassword' WHERE AcName= $AcName  AND ClientID = $ClientId";
       	      
       	
       		$result=0;
				try{	
					$stmt = $conn->prepare($sql);
					$stmt->execute();
					$result= $stmt->rowCount();
				}
				catch(PDOException $e){
					echo $sql . "<br>" . $e->getMessage();
				}
				if ( $result!= 0) {
						
						$response["success"] = 1;
						$response["roweffected"] = $result;
					
				     	$response["message"] = "Update Successfully";
						// echoing JSON response
						echo json_encode($response);
				}else{
						$response["success"] = 0;
						$response["roweffected"] = $result;      
						$response["message"] = "Not updated row ";
						// echoing JSON response
						echo json_encode($response);
				}              
    
} 


?>