Use PHP to do CRUD on a database - Webbprogrammering/websoft GitHub Wiki

This is the assignment A05 for "Section 5: PHP and databases with MySQL/MariaDB".

You should save your work in work/php.

Prerequisites

You should install a web server like XAMPP to be able to retrieve your web pages from the web server.

You have previously attented a course on databases using MySQL so you now your way around the database server and basic SQL.

You attained the lectures on PHP and databases, so you have basic knowledge on how to code PHP and how to connect to a database and run your website through a web server.

Preparations

We are going to build a database driven website using PHP and PHP PDO.

There are some sample code available in the course repo example/php that might be useful.

We are going to build a Create, Read, Update, Delete (CRUD) application.

Start by creating a copy of your work/report to work/php.

# Go to the course repo
cd work
cp -ri report php

Save all your work in the work/php directory.

Requirements grade 3

  1. Update your pages [me,about,report].html and save as .php.

  2. Create a header view/header.php and put the common header elements in it. The other pages should include this file.

  3. Do the same with the footer in view/footer.php.

  4. Apply a common page structure to [me,about,report].php. Where is the PHP-code and where is the HTML-code. Prepare to make it easy to build more pages.

  5. Update your database table to use an auto incremented integer as primary key.

  6. Create a new page search.php (using your common header and footer) that is a basic search engine that uses a HTML form and connects to your database and performs a wildcard search in the tech table (or another table of your choice). Ensure that the table contains at least 7 rows and three columns.

  7. All pages should be placed to your website navbar.

Requirements grade 4

  1. Do all requirements for grade 3.

  2. Create a page create.php to enable to create new rows into the table.

  3. Create a page update.php to enable to update the values of a row in the table.

Requirements grade 5

  1. Do all requirements for grade 4.

  2. Create a page delete.php to enable to delete rows from the table.

  3. Create a page read.php to list the content of the table as a HTML table. Add links to click to provide easy navigation, by clicking a link, to create, update, delete the items in the database table. It should be possible to click on links to navigate and do all CRUD to the table.

  4. Optional. Organise your code by separating HTML from PHP by adding all HTML-parts of [search,create,update,delete,read].php as views in view/[search,create,update,delete,read].php. Its called separation of concerns.