Part 5. Adding an item to the list


Friconix is a site for adding icons to HTML pages. As for Bootstrap or Google Fonts, just include a file in the header of the page to access the site's icons. Go to the Friconix documentation and add the Friconix library to the /list/index.php page.

Check that you can insert icons in the page.

Adding a Form

In the /list/index.php page, add an add form for a new article using Bootstrap's documentation on the bundled form and show/hide items. The form should look as follows on the medium and large screens broad:

Form to add an item to the list

and in the following way on the narrow screen :

Form to add an item to the list

The item name is a required field, but the quantity is optional.

In the form, add two hidden fields which will contain:

The form must send the data with the POST method to the script /list/add.php. Check that the data is sent before continuing.

Function to add an item

In the /lib/lib.php library, add a function addArticle($db, $id_list, $name, $quantity=NULL) which allows you to add an item to a list. Before testing your function, you will need to modify the quantity field in the articles table so that this one can accept zero values. Make the change in phpMyAdmin.

Test your function before continuing.

Processing script

Modify the /list/add.php file, so that :

  1. check the existence of the login and security key fields in the list. If they do not exist, redirect to the home page with an error message.
  2. connect to the database.
  3. check that the security key is associated with the list ID using the getListData function.
  4. remove spaces before and after the item name.
  5. check that the name is not empty.
  6. add the item to the database.
  7. redirect to the list page.

Test your function and check with phpMyAdmin that the new article has has been added to the articles table.

See also

Last update : 11/24/2021