Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP File Handling with PHP Parsing Specific Formats Writing JSON

JSON 404 NOT FOUND

Not Found

The requested URL /inc/write_json.php was not found on this server.

My code is as follows: <?php

$new_book = [ 'title' => filter_input(INPUT_POST, 'title', FILTER_SANITIZE_STRING), 'link' => filter_input(INPUT_POST, 'link', FILTER_SANITIZE_URL), 'book_image_url' => filter_input(INPUT_POST, 'book_image_url', FILTER_SANITIZE_URL), 'book_description' => filter_input(INPUT_POST, 'book_description', FILTER_SANITIZE_STRING), 'num_pages' => filter_input(INPUT_POST, 'num_pages', FILTER_SANITIZE_NUMBER_INT), 'author_name' => filter_input(INPUT_POST, 'author_name', FILTER_SANITIZE_STRING), 'isbn' => filter_input(INPUT_POST, 'isbn', FILTER_SANITIZE_NUMBER_INT), 'average_rating' => filter_input(INPUT_POST, 'average_rating', FILTER_SANITIZE_NUMBER_FLOAT), 'book_published' => filter_input(INPUT_POST, 'book_published', FILTER_SANITIZE_NUMBER_INT) ];

$file = '../data/json/top_programming_books.json'; $books = json_decode(file_get_contents($file));

if (is_object($books->collection->books[0])) { $books->collection->books[] = $new_book; }

$json = json_encode($books); echo '<pre>' . $json . '</pre>';