Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

DrunkenToast/webshop-php-mysql

Repository files navigation

Peter Leconte 2AD1 r0830684

Webshop PHP & MySQL

Important note!

Since I use docker the hostname for the database is not localhost but database instead.
You need to change the default value to your hostname in file webshop/include/class/db.php.

public function __construct(
  $p_host = "database", // <- Change here! Line 17
  • SQL dump is in webshop/SQL/webshop.sql
  • This website was developed in Firefox, quickly checked in Chromium.
  • Table pictures in SQL supports multiple pictures for one product. I did this for future proofing but ended up just always taking the first picture.

Some dummy accounts:

E-mail Password Role
peter5leconte@gmail.com test1234 admin
example@email.com test1234 normal user
test@gmail.com TEST1234 admin
test@test.com test1234 normal user

The admin panel can be found at admin.php or by clicking on your name in the navbar and clicking Admin panel.

Checklist

Hand-in

  • Your webshop
    • Everything in this root folder
  • SQL file to load database
    • webshop/SQL/webshop.sql SQL dump
  • ER diagram
    • webshop/ERD.png
      • ERD.png
    • webshop/phpmyadmin_diagram.png
      • phpmyadmin_diagram.png

Features

  • Gewone gebruiker
    • Kan minstens 1 site bekijken
    • Kan producten zien
      • Kan weergave veranderen (filter) mbv AJAX
    • Kan zich registreren
      • Controleer met JS
      • Geen dubbele registraties
    • Heeft geen toegang tot sites van geregistreerde gebruikers en administrators
  • Geregistreerde gebruiker
    • Kan zich inloggen/uitloggen
    • Kan producten aan winkelmandje toevoegen
    • Bestelling plaatsen
    • Bestelling moet in databank opgeslagen worden
      • Betalen moet niet echt gebeuren, maar wel in database registreerd worden
    • Heeft geen toegang tot admin sites
  • Administrators
    • Mogelijkheid voor meerdere admins
    • Database inhoud aanpassen
      • Gebruikers
        • Toevoegen/verwijderen
          • Verwijderen is deactivate. Hierdoor blijven linken bestaan en kunnen ze later nog geheractiveerd worden.
        • Rechten aanpassen
      • Producten aanpassen/verwijderen/toevoegen
        • Verwijderen is deactivate. Hierdoor blijven linken bestaan en kunnen ze later nog geheractiveerd worden.
    • Zorg voor een duidelijk interface (admin moet het kunnen gebruiken zonder kennis database/php)

Technical requirements

  • HTML5 output is 100% valid (validator)
    • Navbar
      • Admin
      • User
      • Logged out
    • admin
    • manage
      • products
      • cats
      • users
    • cart
    • index
    • login
    • products
    • profile
    • register
  • Gebruik css reset
  • Enkel external css
  • Database
    • Correcte opbouw -> geen herhaling van gegevens etc
    • ER diagram
    • User 'Webuser' met wachtwoord 'Lab2021' dat enkel vereiste perms heeft
  • Error handling
    • Formulieren en bewerkingen mogen geen crash veroorzaken
      • Verdachte/verboden acties opvangen
    • Loggen in file
      • logs/errors.log
    • Gebruik toplevel error handler en toplevel exception handler
      • include/errors.php
    • Minstens 1 try-catch
  • Geen HTML/SQL injectie
    • Hopelijk toch niet ergens vergeten :) (DB class gebruikt prepare, uitzonderingen hebben sqli escape functie of worden gecast. Uit database -> htmlspecialchars)
  • 3 groepen (gewone, geregistreerde, admins) met toegang tot verschillende delen
  • Gebruik functies waar mogelijk
  • Gebruik minstens 1 JOIN

SQL

SQL dump is available in webshop/SQL/webshop.sql.

Table creation

USE webshop;

CREATE TABLE roles (
    ID int unsigned AUTO_INCREMENT,
    name varchar(64) NOT NULL,
  	PRIMARY KEY (ID)
);

CREATE TABLE users (
    ID bigint(8) unsigned AUTO_INCREMENT,
    firstName varchar(64) NOT NULL,
    lastName varchar(64) NOT NULL,
    email varchar(255) NOT NULL,
    passwordHash varchar(255) NOT NULL,
    address varchar(128) NOT NULL,
    billingAddress varchar(128),
    phone varchar(64),
    DOB date,
    DOC DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    roleID int unsigned NOT NULL,
    active TINYINT(1) default 1 NOT NULL,
  	PRIMARY KEY (ID),
    FOREIGN KEY (roleID) REFERENCES roles(ID)
);

CREATE TABLE products (
    ID bigint(8) unsigned AUTO_INCREMENT,
    name varchar(64) NOT NULL,
    description TEXT(2000) NOT NULL,
    unitPrice DECIMAL(10,2) NOT NULL,
    unitsInStock bigint(8) NOT NULL,
    active TINYINT(1) default 1 NOT NULL,
  	PRIMARY KEY (ID)
);

CREATE TABLE categories (
    ID bigint(8) unsigned AUTO_INCREMENT,
    name varchar(64) NOT NULL,
  	PRIMARY KEY (ID)
);

CREATE TABLE productCategory (
    productID bigint(8) unsigned NOT NULL,
    categoryID bigint(8) unsigned NOT NULL,
  	PRIMARY KEY (productID, categoryID),
    FOREIGN KEY (productID) REFERENCES products(ID),
	FOREIGN KEY (categoryID) REFERENCES categories(ID)
);

CREATE TABLE orders (
    ID bigint(8) unsigned AUTO_INCREMENT,
    orderDate date default NULL,
    paymentDate date default NULL,
	  shipDate date default NULL,
    fulfilled TINYINT(1) default 0,
    userID bigint(8) unsigned NOT NULL,
  	PRIMARY KEY (ID),
    FOREIGN KEY (userID) REFERENCES users(ID)
);

CREATE TABLE orderProducts (
    orderID bigint(8) unsigned NOT NULL,
    productID bigint(8) unsigned NOT NULL,
	  amount bigint(8) default 1,
  	PRIMARY KEY (orderID, productID),
    FOREIGN KEY (orderID) REFERENCES orders(ID),
    FOREIGN KEY (productID) REFERENCES products(ID)
);

CREATE TABLE pictures (
    productID bigint(8) unsigned NOT NULL,
	  picturePath varchar(255) NOT NULL,
  	PRIMARY KEY (productID, picturePath),
    FOREIGN KEY (productID) REFERENCES products(ID)
);

Insert basic data

-- User roles
INSERT INTO roles (ID, name) VALUES (1, 'admin');
INSERT INTO roles (ID, name) VALUES (2, 'registered user');
-- A normal visitor is not included, not necessary because no account

About

Webshop in PHP and mySql | School project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published