Beginner to PHP: tips for structure

Hello, I’ve got a background in using C#/Java and HTML/CSS/Wordpress/Joomla before.

My aim is to make a basic student management system using PHP + MySQL.

I’m just wondering how to start. There’s a guide here to make a user registration system which sounds good: https://www.tutorialrepublic.com/php-tutorial/php-mysql-login-system.php

But I’m wondering how PHP actually works in terms of page structure e.g. in HTML you would make an index.html, link to external CSS, make a navigation perhaps, but all with static links which need to be manually changed. If you did make a website like this, pages wouldn’t pass information between each other at all.
JavaScript works well but only client-side.

I’m wondering how PHP handles sessions. In Xamarin you have something called ‘intent’ which is a method that you can use multiple times and insert information to pass on to other pages the user navigates to. How does this work in PHP?

For example, say PHP loads a student table and the user clicks on a button next to a name to edit it. The page may navigate to another page where you can edit the details. But how can you tell the next page to remember which student was selected and which row to edit dynamically?

Thanks. Sorry if I’m a total newbie. Very keen on investing myself into PHP in the following months.

1 Like

Well the main thing you need to know (as you probably already do) is that PHP is not a long running process, but it terminates after each request. That means you can’t maintain any state about what the user was doing except for either in a session (for ephemeral data) or in a datastore (for long lived data).

That said, for your example of editing a student I wouldn’t use any state, but rather create a URL that takes a parameter for the student ID. So for example /student/edit/123 to edit student 123. Then when a user visits that URL you load the student from the database and display an edit form.

The main advantage of this over the session approach is that I can have as many tabs open to edit different students as I like, which is not possible with the session approach.

Also, state makes everything hard. If you can solve something with state or without state you should always opt for solving it without state.

5 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.