---
title: "PHP script returning JSON not working"  
description: "PHP script returning JSON not working"  
author: "Anonymous User"  
published: 2013-05-02  
updated: 2013-05-02  
canonical: https://www.mindstick.com/forum/793/php-script-returning-json-not-working  
category: "php"  
tags: ["php"]  
reading_time: 1 minute  

---

# PHP script returning JSON not working

Hi Guys\
The below returns "\nQuery was empty" as I run it simply from my [server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over) with the [URL](https://www.mindstick.com/forum/436/url-redirection) in the Browser.\
This is the [PHP](https://www.mindstick.com/articles/12149/php-constant-and-php-variables) [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):\

```
    <?$databasehost = "server";$databasename = "xxxx";$databaseusername ="xxxx";$databasepassword = "xxxx";$query = "SELECT * FROM  `Tailor`LIMIT 0 , 30";$con = mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());mysql_select_db($databasename) or die(mysql_error());$query = file_get_contents("php://input"); $sth = mysql_query($query);if (mysql_errno()) {     header("HTTP/1.1 500 Internal Server Error");    echo $query.'\n';    echo mysql_error(); }else{    $rows = array();    while($r = mysql_fetch_assoc($sth)) {        $rows[] = $r;    }    print json_encode($rows);}?>
```

\
**Thanks**

## Replies

### Reply by AVADHESH PATEL

Hi Pravesh!\
\
There is no need to use file_get_content and you have to put one white space after table name.\
\

```
<?php$databasehost = "server";$databasename = "xxxx";$databaseusername ="xxxx";$databasepassword = "xxxx";$query = "SELECT * FROM  `Tailor` LIMIT 0 , 30";$con = mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error()); mysql_select_db($databasename) or die(mysql_error());$sth = mysql_query($query);if (mysql_errno()) { header("HTTP/1.1 500 Internal Server Error");echo $query.'\n';echo mysql_error(); }else{$rows = array();while($r = mysql_fetch_assoc($sth)) {    $rows[] = $r;}print json_encode($rows);}?>
```


---

Original Source: https://www.mindstick.com/forum/793/php-script-returning-json-not-working

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
