Create HTML list from file live?

Good evening community,

I have a question for the programmers and developers among you. I would like to create a list of all the films I particularly liked and save it in a file. I would like a page that displays this list and offers the option to add a new entry.

I'm already somewhat familiar with the basics of HTML, CSS, and the like. I would create a table and fill it with data from the film list file. I would also create a form where I could enter, for example, the title, genre, and rating, and click the submit button to write the new entry to the file.

From software development on Windows, I'm familiar with the INI file format for this kind of thing. The closest comparison I've found so far is JSON. I first tried XML, but failed, and Google suggested that JSON would probably make the most sense.

I managed to read entries from the JSON file, but I couldn't figure out how to modify them, and nothing worked. Now I'm wondering, does this actually make sense? Or is there a much simpler way to achieve my goal?

How would an experienced developer approach this?

I have a web server with PHP and other things. I don't have root access, if that's relevant.

(2 votes)
Loading...

Similar Posts

Subscribe
Notify of
2 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
regex9
1 year ago

How would an experienced developer get it?

Only the requirements are determined, then what is needed and what the individual processes/applications look like.

Now I’m just wondering, does that make sense?

Your concept is all right. You can save the data in JSON, but it would also be conceivable to have a CSV format or the data will be stored directly in a database.

At least when writing the data, you should write a PHP script that accepts, evaluates and writes the form data into your data source.

Suppose you stay with JSON format, then you would have to read and parse the existing data first, then add the new entries and then you could write the result back to the file.

Example for updating the file:

$movie = array('name' => '...', 'ranking' => '...', /* ... */);

$content = file_get_contents('movies.json');
$movies = json_decode($content);

array_push($movies, $movie);

$newContent = json_encode($movies);
file_put_contents('movies.json', $newContent);