<?php
    include_once 'opendb.php';
     $response["next_code"] ="";
     $CompID=0;
     if (isset($_POST["comp_id"]))
    {
         $CompID=$_POST["comp_id"]; 
    }
    if($CompID==0) {
         $response["message"] = "Error: Web Co ID invalid";
            // echo no users JSON
            die( json_encode($response));
    }
    if (isset($_POST["AppID"]))
    {
	
        $AppID=$_POST["AppID"] ;
        $client_Code=$_POST["client_Code"] ;
        $sql = "INSERT INTO subsidiary (AppID1,AppID2,comp_id) " .
               " VALUES ('$AppID','$client_Code',0)";
        if ($conn->query($sql) === TRUE)
        {
           $Eno = $conn->insert_id;
           $response["next_code"] = $Eno;

        } else
        {
           die ( "Error in insert Req :" . $sql . "<br>" . $conn->error);
        } 

    }
    else
    {
        $response["message"] = "Error : No Data for app id";
    }
    
    $conn->close();
    echo json_encode($response);
?>