title: Trying to use JSON but getting '500 Internal Server Error'
body: <p>I'm back with another question.</p>
  
  <p>I'm trying to create a JSON file that gets data from my MySQL database. The thing is, I'm getting the '500 Internal Server Error' message.</p>
  
  <p>The Code:</p>
  
  <pre><code>&lt;?php
  
  header('Content-Type: application/json');
  
  if (!isset($_GET['query'])) {
      echo json_encode([]);
      exit();
  }
  
  $db = new PDO('mysql:host=127.0.0.1;dbname=mydbname', 'mydbuser', 'mydbpaswd');
  
  $users = $db-&gt;prepare("SELECT id, username FROM users WHERE username LIKE :query");
  
  $users-&gt;execute(['query' =&gt; "{$_GET['query']}%"]);
  
  echo json_encode($users-&gt;fetchAll());
  ?&gt;
  </code></pre>
  
  <p>I typed in <a href="http://mylink.com/users.php?query=ch" rel="nofollow">http://mylink.com/users.php?query=ch</a> this should have given me a page with possible usernames starting with 'ch'.</p>
  
  <p>P.S. I used basic names for some things to not show my actual names.</p>
  
  <p>Thanks, in advance.</p>