<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  $userid = 'bizcloud2uapi';
  $pwd = 'j9YlYnY5m@3d';
  $authString = base64_encode($userid . ':' . $pwd);

  $page = 1;
  $query_type = 'category';
  $item_no = '';
  $custno = '';
  $start_date = '';
  $end_date = '';
  $location_code = '';
  $group_code = '';
  $cat_code = 'BAC';
  $dept_code = '';
  $payment_code = '';

  $url = 'http://localhost/newcompany/api/api.asp?';
  $url .= 'page=' . urlencode($page) . '&';
  $url .= 'query_type=' . urlencode($query_type) . '&';
  $url .= 'item_no=' . urlencode($item_no) . '&';
  $url .= 'custno=' . urlencode($custno) . '&';
  $url .= 'start_date=' . urlencode($start_date) . '&';
  $url .= 'end_date=' . urlencode($end_date) . '&';
  $url .= 'location_code=' . urlencode($location_code) . '&';
  $url .= 'group_code=' . urlencode($group_code) . '&';
  $url .= 'cat_code=' . urlencode($cat_code) . '&';
  $url .= 'dept_code=' . urlencode($dept_code) . '&';
  $url .= 'payment_code=' . urlencode($payment_code);

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Authorization: ' . $authString,
    'Content-Length: 0'
  ));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

  $response = curl_exec($ch);
  // Decode the JSON response
    $data = json_decode($response);

    // Check if the JSON decoding was successful
    if ($data === null && json_last_error() !== JSON_ERROR_NONE) {
    echo 'Error: Invalid JSON response.';
    exit;
    }

    // Use the data from the response
    print_r($data);

  curl_close($ch);

//   echo $response;
}
?>
<form method="post" action="">
  <input type="submit">
</form>
