Theo Theo - 1 year ago 50
PHP Question

Backend JSON response

I have created a CMS and tested it in localhost and read all the json responses. However, when I put the code in a live server, I can still insert, view and edit data but I can't read any json responses. And this is a crusial part, as I need them for my android app.

Here is my code.

include ("../includes/connect.php");

$string = "";
$newString = "";
$get_posts = "select * from last_game";
$run_posts = mysqli_query($con, $get_posts);
$posts_array = array();

while ($posts_row = mysqli_fetch_array($run_posts))
$row_array['id'] = $posts_row['id'];
$row_array['game'] = $posts_row['game'];
$row_array['date'] = $posts_row['date'];
array_push($posts_array, $row_array);

$string = json_encode($posts_array, JSON_UNESCAPED_UNICODE);
echo $string;

There error I am getting is

Notice: Use of undefined constant JSON_UNESCAPED_UNICODE - assumed
'JSON_UNESCAPED_UNICODE' in /var/www/vhosts/theo- on line 26

Warning: json_encode() expects parameter 2 to be long, string given in
/var/www/vhosts/theo- on line 26

Could it be something wrong with the php version?

Any ideas?



Probably your MySQL connection needs different credential on live server: check your connect.php to be sure mysql host/user/password and db name are correct.

You can check what server response by manually point your browser to remote server and see what's happening, probably you should enable debugging with something like: error_reporting(E_ALL); ini_set("display_errors", 1);

important: remember to remove those lines when going in production !