diff --git a/02/index.php b/02/index.php index f38ef21..aa49b70 100644 --- a/02/index.php +++ b/02/index.php @@ -1,79 +1,60 @@ - Hello there, my name is ". $firstName . " ". $lastName ."

"; - -if($isInstructor) { - echo "

I am your teacher.

"; -} -else { - echo "

Whoops, teach didn't show!

"; -} - -//3. PHP is loosely typed -//create two variables, one called num1 and one called num2, in num1 store an integer and in num2 store a number but treat as string "10" - -$num1 = 10; //integer -$num2 = "10"; //string - -//add type hints to make PHP less loosey goosey -/*function add(int $num1, int $num2) : int { - return $num1 + $num2; +// inline comment +//3. Variables, Data Types, Concatenation, Conditional Statements & Echo + +$firstName = "Keifer"; // string +$lastname = "Grainger"; // string +$age = 22; // integer +$isStudent = true; // boolean + +echo "

Hello, my name is " . $firstName . " " . $lastname . "

"; +if ($isStudent) { + echo "

I am a student

"; +} else { + echo "

I am not a student.

"; } +//4. Loosely Typed Language Demo -echo "

" . add($num1,$num2) . "

"; - -*/ +$num1 = 1; +$num2 = 10; -// OOP with PHP { - -class Person { - public string $name; - public int $age; - public bool $isInstructor; - - public function __construct(string $name, int $age, bool $isInstructor) { - $this->name = $name; - $this->age = $age; - $this->isInstructor = $isInstructor; - } - - public function getBadge(): string { - $role = $this->isInstructor ? "Instructor" : "Student"; - return "Name : {$this->name} | Age: {$this->age} | Role : $role"; - } +function add(int $num1,int $num2) : int { + return $num1 + $num2; } -//create an instance of the object +echo "

" . add($num1, $num2) . "

"; -$person = new Person("Jessica", 40, true); - -echo $person->getBadge(); +echo "

Hello there, my name is " . $firstname . " " . $lastName . "

"; +if ($is_student === true) { + echo "

I am your teacher!

"; +} else { + echo "

Uh oh, teach didn't show!

"; +} +//3. PHP is loosely typed +$num1 = 5; +$num2 = "10"; +echo "

" . add($num1, $num2) . "

"; +//4. Strict Types & Types Hints +/* Add declare(strict_types=1) and type hints +//strict types tell PHP not to automatically convert values when calling functions. Type hints tell PHP what to expect */ +/*function add(int $num1, int $num2): int { + return $num1 + $num2; +} +echo add($num1, $num2); +*/ +//6. OOP with PHP diff --git a/03/02_fix_this_code/index.php b/03/02_fix_this_code/index.php index 19aa44c..e38da09 100644 --- a/03/02_fix_this_code/index.php +++ b/03/02_fix_this_code/index.php @@ -21,4 +21,4 @@ catch (PDOException $e { echo "Database error: " . $e -} +} \ No newline at end of file diff --git a/assignments/labs/lab_four/includes/connect.php b/assignments/labs/lab_four/includes/connect.php new file mode 100644 index 0000000..d063fe7 --- /dev/null +++ b/assignments/labs/lab_four/includes/connect.php @@ -0,0 +1,7 @@ + PDO::ERRMODE_EXCEPTION] +); \ No newline at end of file diff --git a/assignments/labs/lab_four/process.php b/assignments/labs/lab_four/process.php index 4dd4476..16ce15f 100644 --- a/assignments/labs/lab_four/process.php +++ b/assignments/labs/lab_four/process.php @@ -1,17 +1,30 @@ prepare(" + INSERT INTO subscribers (first_name, last_name, email) + VALUES (:first_name, :last_name, :email) +"); + +$STMT->execute([ + ":first_name" => $FIRST_NAME, + ":last_name" => $LAST_NAME, + ":email" => $EMAIL +]); ?> @@ -28,13 +41,14 @@

Thank You for Subscribing

- - +

+ Thanks, ! + You have been added to our mailing list. +

View Subscribers

- - \ No newline at end of file + diff --git a/assignments/labs/lab_four/subscribers.php b/assignments/labs/lab_four/subscribers.php index ff6bbf0..e5b7bd4 100644 --- a/assignments/labs/lab_four/subscribers.php +++ b/assignments/labs/lab_four/subscribers.php @@ -1,5 +1,4 @@ prepare(" + SELECT id, first_name, last_name, email, subscribed_at + FROM subscribers + ORDER BY subscribed_at DESC +"); + +$STMT->execute(); +$subscribers = $STMT->fetchAll(); ?>
@@ -31,7 +37,15 @@ - + + + + + + + + + @@ -39,6 +53,4 @@

Back to Subscribe Form

-
- - + \ No newline at end of file diff --git a/assignments/labs/lab_one/car.php b/assignments/labs/lab_one/car.php new file mode 100644 index 0000000..39fde42 --- /dev/null +++ b/assignments/labs/lab_one/car.php @@ -0,0 +1,22 @@ +make = $make; + $this->model = $model; + $this->year = $year; + } + + // Method to get car details + public function getDetails(): string { + return $this->year . " " . $this->make . " " . $this->model; + } +} \ No newline at end of file diff --git a/assignments/labs/lab_one/connect.php b/assignments/labs/lab_one/connect.php new file mode 100644 index 0000000..3ab3604 --- /dev/null +++ b/assignments/labs/lab_one/connect.php @@ -0,0 +1,21 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + // echo "Connected successfully"; // optional for testing +} catch (PDOException $e) { + // Display error message if connection fails + echo "Database connection failed: " . $e->getMessage(); + exit; +} diff --git a/assignments/labs/lab_one/footer.php b/assignments/labs/lab_one/footer.php index 78e2b2b..fd8438f 100644 --- a/assignments/labs/lab_one/footer.php +++ b/assignments/labs/lab_one/footer.php @@ -1,3 +1,4 @@ + Car: " . $car->getDetails() . "

"; + +// Output instructions message echo "

Follow the instructions outlined in instructions.txt to complete this lab. Good luck & have fun!😀

"; -require "footer.php"; \ No newline at end of file + +/* +Reflection: +I found creating the Car class and using require statements easy +because it followed examples from class. The most challenging part +was setting up the PDO database connection and making sure XAMPP +was configured correctly. +*/ + +// Include shared footer HTML +require "footer.php"; \ No newline at end of file diff --git a/assignments/labs/lab_three/index.php b/assignments/labs/lab_three/index.php new file mode 100644 index 0000000..41aa15b --- /dev/null +++ b/assignments/labs/lab_three/index.php @@ -0,0 +1,94 @@ + + + + + + Contact Form + + + + + + + +
+ +

Contact Form

+

All fields are required.

+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + + + +
+
+ + + \ No newline at end of file diff --git a/assignments/labs/lab_three/process.php b/assignments/labs/lab_three/process.php new file mode 100644 index 0000000..4c15bb6 --- /dev/null +++ b/assignments/labs/lab_three/process.php @@ -0,0 +1,156 @@ + 40) $errors[] = "First name is too long."; +if (strlen($lastName) > 40) $errors[] = "Last name is too long."; +if (strlen($email) > 80) $errors[] = "Email is too long."; +if (strlen($message) > 1000) $errors[] = "Message is too long."; + +// Email format validation +if ($email !== "" && !filter_var($email, FILTER_VALIDATE_EMAIL)) { + $errors[] = "Email address is not valid."; +} + +// ------------------------------------ +// Display errors if validation fails +// ------------------------------------ +if (!empty($errors)) { + ?> + + + + + Form Error + + + +
+
+

Please fix the following:

+ +
+ Go back +
+ + + + + + + + Form Submitted + + + +
+ +
+

Submission received

+

Your form was successfully submitted.

+
+ + +

First Name:

+

Last Name:

+

Email:

+

Message:

+ + + +
Email was sent successfully.
+ +
+ Email could not be sent (common on local servers). +
+ + + Submit another message + +
+ + \ No newline at end of file diff --git a/assignments/labs/lab_two/data.php b/assignments/labs/lab_two/data.php new file mode 100644 index 0000000..1610764 --- /dev/null +++ b/assignments/labs/lab_two/data.php @@ -0,0 +1,6 @@ + +

© 2026

+ + + + diff --git a/assignments/labs/lab_two/includes/header.php b/assignments/labs/lab_two/includes/header.php new file mode 100644 index 0000000..e7bf5b3 --- /dev/null +++ b/assignments/labs/lab_two/includes/header.php @@ -0,0 +1,9 @@ + + + + + <?= $title ?> + + + +

diff --git a/assignments/labs/lab_two/includes/nav.php b/assignments/labs/lab_two/includes/nav.php new file mode 100644 index 0000000..687eb96 --- /dev/null +++ b/assignments/labs/lab_two/includes/nav.php @@ -0,0 +1,5 @@ + diff --git a/assignments/labs/lab_two/index.php b/assignments/labs/lab_two/index.php new file mode 100644 index 0000000..d7b53e5 --- /dev/null +++ b/assignments/labs/lab_two/index.php @@ -0,0 +1,14 @@ + + + + + + + diff --git a/timetracker/add_task.php b/timetracker/add_task.php new file mode 100644 index 0000000..7875235 --- /dev/null +++ b/timetracker/add_task.php @@ -0,0 +1,130 @@ +success) { + $errors[] = "reCAPTCHA verification failed. Please try again."; + } + } + + // If no errors, insert into database + if (empty($errors)) { + $task_name = mysqli_real_escape_string($conn, $_POST['task_name']); + $category = mysqli_real_escape_string($conn, $_POST['category']); + $priority = mysqli_real_escape_string($conn, $_POST['priority']); + $due_date = mysqli_real_escape_string($conn, $_POST['due_date']); + $time_spent = mysqli_real_escape_string($conn, $_POST['time_spent']); + + $sql = "INSERT INTO tasks (task_name, category, priority, due_date, time_spent) + VALUES ('$task_name', '$category', '$priority', '$due_date', '$time_spent')"; + + if (mysqli_query($conn, $sql)) { + // Redirect back to index after successful insert + header("Location: index.php"); + exit(); + } else { + $errors[] = "Something went wrong. Please try again."; + } + } +} +?> + + + + + + Add Task + + + + + + +
+

Add New Task

+ + + +
+ +

+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + +
+
+
+ + Cancel + + +
+
+ + + \ No newline at end of file diff --git a/timetracker/db.php b/timetracker/db.php new file mode 100644 index 0000000..cc16a91 --- /dev/null +++ b/timetracker/db.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/timetracker/delete_task.php b/timetracker/delete_task.php new file mode 100644 index 0000000..92beff1 --- /dev/null +++ b/timetracker/delete_task.php @@ -0,0 +1,18 @@ + \ No newline at end of file diff --git a/timetracker/edit_task.php b/timetracker/edit_task.php new file mode 100644 index 0000000..db866ab --- /dev/null +++ b/timetracker/edit_task.php @@ -0,0 +1,134 @@ + + + + + + + Edit Task + + + + +
+

Edit Task

+ + + +
+ +

+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + Cancel + + +
+
+ + + \ No newline at end of file diff --git a/timetracker/index.php b/timetracker/index.php new file mode 100644 index 0000000..9545c5b --- /dev/null +++ b/timetracker/index.php @@ -0,0 +1,63 @@ + + + + + + + Time Tracker + + + + + +
+

Time Tracker

+ + + + Add Task + + + + + + + + + + + + + + + 0): ?> + + + + + + + + + + + + + + + + +
Task NameCategoryPriorityDue DateTime Spent (hrs)Actions
+ Edit + Delete +
No tasks found. Add one!
+
+ + + \ No newline at end of file