Part 4: Creating the page

We will now create the page that will display the shopping list. First, we will simply create the page with the name of the shopping list.

Creating the page

Take the frame of the home page and create the page /list/index.php in order to include:

The empty shopping list page

Data Recovery

We'll retrieve the information regarding the list from the database. In the PHP library, write a new function getListData($db, $id, $key) which receives parameters :

The function retrieves the data from this list from the database. If the list does not exist or if the key is wrong, use the errorManager function to display the message "This list does not exist. " before redirecting the user to the home page.

The function must return an array containing 3 keys (id, name and ukey) :

array (size=3)
  'id' => string '6' (length=1)
  'name' => string 'fsdfsd' (length=6)
  'ukey' => string 'fTLx45ryKcMPCjoQEotvg5AUxGrxInf0' (length=32)

Test your function before continuing.

Title display

In the list/index.php page, at the very beginning of the code (before the <!doctype html> tag) insert a section in PHP allowing to :

  1. connect to the database;
  2. check the existence of the fields passed in the url (id and key);
  3. retrieve the $list array associated with the requested list using the getListData function.

Once the data is retrieved, replace the temporary title with the name of the list in the header and in the page :

The title of the shopping list displayed

See also

Last update : 01/14/2021