title: I wrote this simple Restful web-service and am getting a blank response. Why?
body: <p>I am learning to write a Restful webservice in PHP. So I followed a video tutorial and wrote the following basic webservice. The problem is that when I tried to access the web service via <code>http://localhost/Test8/?name=c</code> (because my <code>index.php</code> is located in <code>Test8</code> directory) URL, <strong>I get a blank page</strong>. </p>
  
  <p>But when the tutor in the video accessed it using <code>http://localhost/rest/?name=c</code> (because their <code>index.php</code> located in <code>rest</code> directory), <strong>they got <code>{"status":200, "status_message":"Book found", "data":348}</code> in the webpage.</strong></p>
  
  <p><strong>What did I miss?</strong></p>
  
  <p><strong>index.php:</strong></p>
  
  <pre><code>&lt;?php
  
  //Process client's request (via URL)
  header("Content-Type:application/json");
  
  if (  !empty($GET['name'])  ) {
      $name = $GET['name'];
      $price = get_price($name);
  
      if (empty($price)) {
          //Book not found
          deliver_response(200, 'Book not found!', NULL);
      } else {
          //Send the response with book price
          deliver_response(200, 'Book found', $price);
      }
  
  } else {
      //throw invalid request
      deliver_response(400, "Invalid Request", NULL);
  }
  
  
  
   //API Functions
   function get_price($bookRequested) {
       $books = array(
          'Java' =&gt; 999,
          'C' =&gt; 348,
          'PHP' =&gt;500
       );
  
       foreach ($books as $book=&gt;$price) {
           if ($book == $bookRequested) {
               return $price;
           }
       }
   }
  
  
   function deliver_response($status, $status_message, $data) {
       header("HTTP/1.1 $status $status_message");
  
       $response['status'] = $status;
       $response['status_message'] = $status_message;
       $response['data'] = $data;
  
       $json_response = json_encode($response);
   }
  
  ?&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT:</strong></p>
  
  <p><strong>Just checked the console. It says <code>Failed to load resource: the server responded with a status of 400 (Invalid Request)</code>...</strong> </p>
  
  <p>I changed</p>
  
  <pre><code>if (  !empty($GET['name'])  ) {
      ...
  
  } else {
      //throw invalid request
      ...
  }
  </code></pre>
  
  <p><strong><em>to</em></strong></p>
  
  <pre><code>if (  !empty($GET['name'])  ) {
      echo '$GET["name"] is NOT empty';
  
      ...
  
  } else {
      echo '$GET["name"] IS empty';
      //throw invalid request
      ...
  }
  </code></pre>
  
  <p><strong>and the browser prints <code>$GET["name"] IS empty</code>.</strong></p>