1

I'm back with another question.

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.

The Code:

<?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->prepare("SELECT id, username FROM users WHERE username LIKE :query");

$users->execute(['query' => "{$_GET['query']}%"]);

echo json_encode($users->fetchAll());
?>

I typed in http://mylink.com/users.php?query=ch this should have given me a page with possible usernames starting with 'ch'.

P.S. I used basic names for some things to not show my actual names.

Thanks, in advance.

Chris
  • 1,574
  • 4
  • 16
  • 49

1 Answers1

2

The $array = ['myindex' => 'somevalue'] syntax for arrays has been implemented in PHP 5.4. Try with array() instead.

Tom Tom
  • 3,680
  • 5
  • 35
  • 40
  • I'll try upgrading my PHP from 5.3.3 to a newer version and will report back once it's done. Thanks for your comment. – Chris Feb 21 '15 at 14:03