diff --git a/.DS_Store b/.DS_Store index d29bd1f..9a38d83 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/03/.DS_Store b/03/.DS_Store new file mode 100644 index 0000000..1e60644 Binary files /dev/null and b/03/.DS_Store differ diff --git a/03/02_fix_this_code/index.php b/03/02_fix_this_code/index.php index 19aa44c..8c22ae0 100644 --- a/03/02_fix_this_code/index.php +++ b/03/02_fix_this_code/index.php @@ -3,22 +3,21 @@ ini_set('display_errors', 1); error_reporting(E_ALL); - -$host = "localhost" - +$host = "localhost"; $dbname = "week_two"; $username = "root"; $password = ""; -$dsn = "mysql:host=$hostdbname=$dbname"; +// DSN (Data Source Name) +$dsn = "mysql:host=$host;dbname=$dbname"; try { - - $pdo = new PDO($dsn $username,); - $pdo->setAttribute(PDO::ATTR_ERRMODE PDO::ERRMODE_SILENT); + $pdo = new PDO($dsn, $username, $password); - echo "Connected to database!"; + // Set error mode + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); -catch (PDOException $e { - echo "Database error: " . $e + echo "Connected to database!"; +} catch (PDOException $e) { + echo "Database error: " . $e->getMessage(); } diff --git a/03/03_make_it_maintainable/footer.php b/03/03_make_it_maintainable/footer.php new file mode 100644 index 0000000..6e35977 --- /dev/null +++ b/03/03_make_it_maintainable/footer.php @@ -0,0 +1,9 @@ + +
+

© 2026

+ + + diff --git a/03/03_make_it_maintainable/header.php b/03/03_make_it_maintainable/header.php new file mode 100644 index 0000000..b6a9b75 --- /dev/null +++ b/03/03_make_it_maintainable/header.php @@ -0,0 +1,13 @@ + + + + + + My PHP Page + + +

Welcome

+
diff --git a/03/03_make_it_maintainable/index.php b/03/03_make_it_maintainable/index.php index 5cb2b17..f73e81f 100644 --- a/03/03_make_it_maintainable/index.php +++ b/03/03_make_it_maintainable/index.php @@ -1,34 +1,30 @@ ['title' => 'Home', 'content' => 'Welcome to my PHP page.'], + 'about' => ['title' => 'About', 'content' => 'This is the About section.'], + 'contact' => ['title' => 'Contact', 'content' => 'This is the Contact section.'], +]; +$current = $_GET['page'] ?? 'home'; +if (!isset($pages[$current])) { + $current = 'home'; +} ?> - - - - My PHP Page - - + -

Welcome

+

+

- - - - - - + diff --git a/assignments/.DS_Store b/assignments/.DS_Store index b723e72..9d96b89 100644 Binary files a/assignments/.DS_Store and b/assignments/.DS_Store differ diff --git a/assignments/labs/.DS_Store b/assignments/labs/.DS_Store index 1ed5283..925a662 100644 Binary files a/assignments/labs/.DS_Store and b/assignments/labs/.DS_Store differ diff --git a/lab_04/.DS_Store b/lab_04/.DS_Store new file mode 100644 index 0000000..27414eb Binary files /dev/null and b/lab_04/.DS_Store differ diff --git a/lab_04/assets/bitumi.png b/lab_04/assets/bitumi.png new file mode 100644 index 0000000..bb7fe53 Binary files /dev/null and b/lab_04/assets/bitumi.png differ diff --git a/lab_04/css/main.css b/lab_04/css/main.css new file mode 100644 index 0000000..0544c31 --- /dev/null +++ b/lab_04/css/main.css @@ -0,0 +1,127 @@ +* { + box-sizing: border-box; +} + +body { + font-family: system-ui, -apple-system, "Segoe UI", Arial, sans-serif; + background-color: #fff0f6; + color: #333; + line-height: 1.6; +} + +header, +main, +footer { + max-width: 720px; + margin: 2rem auto; + padding: 1.5rem; + background-color: #ffffff; + border-radius: 16px; + border: 1px solid #ffd6e7; +} + +h1 { + text-align: center; + margin-bottom: 1rem; +} + +h1 img { + max-width: 220px; + height: auto; + display: block; + margin: 0 auto; +} + +.nav { + text-align: center; + margin-bottom: 1rem; +} + +.nav a { + text-decoration: none; + color: #d63384; + font-weight: 600; + margin: 0 10px; +} + +.nav a:hover { + text-decoration: underline; +} + +h2 { + text-align: center; + color: #d63384; + margin-bottom: 1.5rem; +} + +fieldset { + border: 1px solid #ffc2da; + border-radius: 12px; + padding: 1.25rem; + margin-bottom: 1.5rem; +} + +legend { + font-weight: bold; + color: #c2185b; +} + +label { + display: block; + margin-top: 0.75rem; + font-weight: 500; +} + +input, +textarea { + width: 100%; + padding: 0.6rem; + margin-top: 0.25rem; + border-radius: 8px; + border: 1px solid #ffc2da; + font-size: 1rem; +} + +input:focus, +textarea:focus { + outline: none; + border-color: #d63384; +} + +table { + width: 100%; + border-collapse: collapse; + margin-top: 1rem; +} + +th, +td { + border: 1px solid #ffd6e7; + padding: 0.75rem; +} + +th { + background-color: #fff0f6; +} + +button { + background-color: #ff4fa3; + color: white; + border: none; + padding: 0.75rem 1.5rem; + border-radius: 999px; + font-size: 1rem; + cursor: pointer; +} + +button:hover { + opacity: 0.9; +} + +footer { + text-align: center; + font-size: 0.9rem; + color: #777; +} + + diff --git a/lab_04/includes/footer.php b/lab_04/includes/footer.php new file mode 100644 index 0000000..30a3b03 --- /dev/null +++ b/lab_04/includes/footer.php @@ -0,0 +1,6 @@ + + + diff --git a/lab_04/includes/header.php b/lab_04/includes/header.php new file mode 100644 index 0000000..42e79bf --- /dev/null +++ b/lab_04/includes/header.php @@ -0,0 +1,23 @@ + + + + + + Bake It Till You Make It + + + + +
+

+ +

+ + + +
diff --git a/lab_04/index.php b/lab_04/index.php new file mode 100644 index 0000000..0fe1299 --- /dev/null +++ b/lab_04/index.php @@ -0,0 +1,72 @@ + + +
+

Place Your Order 🧁

+ +
+ +
+ Your Info + + + + + + + + + +
+ +
+ Pick Treats + + + + + + + + + + + + + + + + + + + + + +
TreatQuantity
Croissant 🥐 + +
Muffin 🌙 + +
Eclair 🤔 + +
+
+ +
+ Notes (optional) + + + +
+ +

+ +

+ +
+
+ + + diff --git a/lab_04/process.php b/lab_04/process.php new file mode 100644 index 0000000..7ce9725 --- /dev/null +++ b/lab_04/process.php @@ -0,0 +1,74 @@ + + + $qty) { + if (filter_var($qty, FILTER_VALIDATE_INT) !== false && $qty > 0) { + $orderedItems[$item] = $qty; + } +} + +if (count($orderedItems) === 0) { + $errors[] = "Please order at least one treat."; +} +?> + +
+ + + +

Something went wrong 😬

+ + + + +

Thanks for your order, ! 🎉

+ +

We’ve received the following items:

+ + + + +

Notes:

+ + + + +
+ + diff --git a/lab_04/send_email.php b/lab_04/send_email.php new file mode 100644 index 0000000..f1862fc --- /dev/null +++ b/lab_04/send_email.php @@ -0,0 +1,11 @@ +setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); +} +//what happens if there is an error connecting +catch(PDOException $e) { + die("Database connection failed: " . $e->getMessage()); +} \ No newline at end of file diff --git a/week-5/includes/footer.php b/week-5/includes/footer.php new file mode 100644 index 0000000..29d99ae --- /dev/null +++ b/week-5/includes/footer.php @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/week-5/includes/header.php b/week-5/includes/header.php new file mode 100644 index 0000000..fe20432 --- /dev/null +++ b/week-5/includes/header.php @@ -0,0 +1,26 @@ + + + + + + + Week 4 - Form Validation + + + + + +
+

+ +

+ +
\ No newline at end of file diff --git a/week-5/index.php b/week-5/index.php new file mode 100644 index 0000000..be3af0d --- /dev/null +++ b/week-5/index.php @@ -0,0 +1,114 @@ + +
+

Order Online - Easy & Simple (And Totally Secure...) 🧁

+
+ + + +
+ Customer Information + + + + + + + + + + +
+ + +
+ Order Details + +

+ Enter a quantity for each item (use 0 if you don't want it). +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Baked TreatQuantity
Chaos Croissant 🥐 + + +
Midnight Muffin 🌙 + + +
Existential Éclair 🤔 + + +
Procrastination Cookie ⏰ + + +
Finals Week Brownie 📚 + + +
Victory Cinnamon Roll 🏆 + + +
+ +
+ +
+ Additional Comments + +

+
+ +

+
+ +

+ +

+ +
+
+ + + + + \ No newline at end of file diff --git a/week-5/order.php b/week-5/order.php new file mode 100644 index 0000000..61c73be --- /dev/null +++ b/week-5/order.php @@ -0,0 +1,79 @@ + + +
+

Orders

+ + +

No orders yet.

+ + + + +

+ Back to Order Form +

+
+ + \ No newline at end of file diff --git a/week-5/orders.sql b/week-5/orders.sql new file mode 100644 index 0000000..0e6a0ec --- /dev/null +++ b/week-5/orders.sql @@ -0,0 +1,9 @@ + +CREATE TABLE orders ( + id INT AUTO_INCREMENT PRIMARY KEY, + customer_name VARCHAR(100) NOT NULL, + email VARCHAR(150) NOT NULL, + item VARCHAR(50) NOT NULL, + quantity INT NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); diff --git a/week-5/process.php b/week-5/process.php new file mode 100644 index 0000000..6c5c962 --- /dev/null +++ b/week-5/process.php @@ -0,0 +1,146 @@ + ['regexp' => '/^[0-9\-\+\(\)\s]{7,25}$/'] +])) { + $errors[] = "Phone number format is invalid."; +} + +// Address: required +if ($address === null || $address === '') { + $errors[] = "Address is required."; +} + +// Validate order quantities +// We only accept items with an integer quantity > 0. +$itemsOrdered = []; + +foreach ($items as $item => $quantity) { + if (filter_var($quantity, FILTER_VALIDATE_INT) !== false && $quantity > 0) { + $itemsOrdered[$item] = $quantity; + } +} + +// Require at least one item to be ordered +if (count($itemsOrdered) === 0) { + $errors[] = "Please order at least one item."; +} + +// If there are errors, show them and stop the script before inserting to the DB +if (!empty($errors)) { + require "includes/header.php"; + echo "
"; + echo "

Please fix the following:

"; + echo ""; + echo "
"; + + require "includes/footer.php"; + exit; +} + + +/* +INSERT THE ORDER USING A PREPARED STATEMENT +*/ + +//set up the query +$sql="INSERT INTO orders(first_name, last_name, phone, address, email, chaos_croissant, midnight_muffin, extintial_eclair, procrastion_cookie, final_week_brownie, victory_cinnomon_roll, comments) values (:first_name, :last_name, :phone , :address, :email, :chaos_croissant,:midnight_muffin, :extintial_eclair, :procrastion_cookie, :final_week_brownie, :victory_cinnomon_roll, :comments"; + +//prepare the query + +$stmt=$pdo->prepare($sql); + +$chaosCroissant=$itemsOrdered['chaos_croissant']??0; +$midnightMuffin=$itemsOrdered['midnight_muffin']??0; +$extintialEclair=$itemsOrdered['extintial_eclair']??0; +$procrastionCookie=$itemsOrdered['procrastion_cookie']??0; +$finalWeekBrownie=$itemsOrdered['final_week_brownie']??0; +$victoryCinnomonRoll=$itemsOrdered['victory_cinnomon_roll']??0; + + + + + + +$stm->bindPram(':$first_name', $firstName); +$stm->bindPram(':$last_name', $lastName); +$stm->bindPram(':phone', $phone); +$stm->bindPram(':address', $address); +$stm->bindPram(':$email', $email); +$stm->bindPram(':$', $email); +$stm->bindPram(':comments', $comments); + + +$stm->bindPram(':chaos_croissant', $chaosCroissant); +$stm->bindPram(':midnight_muffin', $midnightMuffin); +$stm->bindPram(':extintial_eclair', $extintialEclair); +$stm->bindPram(':procrastion_cookie', $procrastionCookie); +$stm->bindPram(':final_week_brownie', $finalWeekBrownie); +$stm->bindPram(':victory_cinnomon_roll', $victoryCinnomonRoll); + + +//execute -i.e run the query +$stm->execute(); + + +//pull from $itemOrdered and store in variables + +?> + + + +
+

Thank you for your order, !

+

+ We’ve received your order and will contact you at + . +

+
+ + \ No newline at end of file diff --git a/week-5/styles/main.css b/week-5/styles/main.css new file mode 100644 index 0000000..39cf0a4 --- /dev/null +++ b/week-5/styles/main.css @@ -0,0 +1,134 @@ +/* ============================ + Simple Reset / Base Styles + ============================ */ + +/* Box sizing reset */ +*, +*::before, +*::after { + box-sizing: border-box; +} + +/* Remove default margins */ +body, +h1, +h2, +h3, +p, +fieldset, +legend { + margin: 0; +} + +/* Base body styles */ +body { + line-height: 1.5; + color: #222; + background-color: #fafafa; +} + +/* ============================ + Layout + ============================ */ + +main, +header nav, +footer { + max-width: 80%; + margin: 2rem auto; + padding: 1.5rem; +} + +/* ============================ + Logo / Heading + ============================ */ + +h1 { + text-align: center; + margin-bottom: 1.5rem; +} + +h1 img { + max-width: 220px; + height: auto; +} + +/* ============================ + Form Elements + ============================ */ + +fieldset { + border: 1px solid #ddd; + padding: 1rem; + margin-bottom: 1.5rem; +} + +legend { + padding: 0 0.5rem; + font-weight: 600; +} + +label { + font-weight: 500; +} + +input, +select, +textarea, +button { + display:block; + font-family: inherit; + font-size: 1rem; +} + +input, +select, +textarea { + width: 100%; + padding: 0.4rem; + margin-top: 0.25rem; +} + +textarea { + resize: vertical; +} + +/* ============================ + Navigation + ============================ */ + +nav { + margin-bottom: 1.5rem; + background-color: #333; +} + +nav ul { + list-style: none; + padding: 0; + margin: 0; + + display: flex; + gap: 1.25rem; + justify-content: center; +} + +nav a { + text-decoration: none; + color: #fff; + font-weight: 500; + padding: 0.25rem 0; +} + +nav a:hover, +nav a:focus { + text-decoration: underline; +} + +/* ============================ + Footer + ============================ */ + + footer { + background-color: #000; + color: #FFF; + } \ No newline at end of file