$fname, "message" => $fmsg); # Setup JSON $data = json_decode(file_get_contents('test.json'), true); # Add array_unshift($data , $savemsg); # Check name and message if ($fname == "") { echo "There is no name, Try again with a name"; exit(); } if ($fmsg == "") { echo "There is no message, Try again with a message"; exit(); } file_put_contents('test.json', json_encode($data, JSON_PRETTY_PRINT)); echo $fmsg;