Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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>';