0

so I have a simple code to post data to database

<?php 
$data = json_decode(file_get_contents("php://input"));
$review = mysql_real_escape_string($data->review);
mysql_connect("localhost", "root", ""); 
mysql_select_db("reherse");
mysql_query("INSERT INTO reviews('review') VALUES('".$review."')");
?>

But it's getting me to an error 'Trying to get property of non-object'. I'm new in PHP so It might be some stupid mistake.

vitr
  • 6,766
  • 8
  • 30
  • 50
Oleg V
  • 275
  • 2
  • 12
  • on which line you are getting error? It is possible that some wrong data in the file. – Pirate Jul 17 '16 at 21:45
  • just a guess with the info you give, but your json_decode is probably failing , thus `$data` is not an object and `$data->review` attempts to get a property of a non-object. Try to echo `json_last_error_msg()` to get a hint. – YvesLeBorg Jul 17 '16 at 21:54

0 Answers0