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 @@+ Thanks, = htmlspecialchars($FIRST_NAME) ?>! + You have been added to our mailing list. +
- -