From 93f0ef8f1def945b5e46de64beae04ecca5a08eb Mon Sep 17 00:00:00 2001 From: Shaun Date: Wed, 9 Jan 2019 13:28:42 +0000 Subject: [PATCH 01/38] lesson-1 --- README.md | 5 ----- index.php | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) delete mode 100644 README.md create mode 100644 index.php diff --git a/README.md b/README.md deleted file mode 100644 index 4996344..0000000 --- a/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# php-mysql-tutorial -All the course files for the PHP & MySQL for Beginners tutorial on The Net Ninja YouTube channel. - -# how to use -To see the code for a particular lesson, be sure to select that lesson branch from the branch dropdown (top-left). diff --git a/index.php b/index.php new file mode 100644 index 0000000..423542e --- /dev/null +++ b/index.php @@ -0,0 +1,15 @@ + + + + + + my first PHP file + + +

+ + \ No newline at end of file From 6386a486ebdacbe40dacd394faba8a47c99594f7 Mon Sep 17 00:00:00 2001 From: Shaun Date: Wed, 9 Jan 2019 13:39:56 +0000 Subject: [PATCH 02/38] lesson-4 --- index.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index 423542e..7e66e20 100644 --- a/index.php +++ b/index.php @@ -1,15 +1,26 @@ - my first PHP file + PHP Tutorials -

+ +

User profile page

+ +
+
+ \ No newline at end of file From ce9c87d28b810ca1e6ad6b1a35099150357cabfb Mon Sep 17 00:00:00 2001 From: Shaun Date: Wed, 9 Jan 2019 14:12:20 +0000 Subject: [PATCH 03/38] lesson-5 --- index.php | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/index.php b/index.php index 7e66e20..898dc7f 100644 --- a/index.php +++ b/index.php @@ -1,12 +1,30 @@ @@ -17,10 +35,7 @@ -

User profile page

- -
-
+

\ No newline at end of file From c2f3f0f39a4b94c76c75f1e844cf5b1e25720785 Mon Sep 17 00:00:00 2001 From: Shaun Date: Wed, 9 Jan 2019 18:00:59 +0000 Subject: [PATCH 04/38] lesson-6 --- index.php | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/index.php b/index.php index 898dc7f..7def290 100644 --- a/index.php +++ b/index.php @@ -1,30 +1,35 @@ @@ -35,7 +40,7 @@ -

+

\ No newline at end of file From 6fe7162ec4fe9651f1216af011458f8c6aa172c9 Mon Sep 17 00:00:00 2001 From: Shaun Date: Wed, 9 Jan 2019 18:33:53 +0000 Subject: [PATCH 05/38] lesson-7 --- index.php | 54 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/index.php b/index.php index 7def290..3dedffd 100644 --- a/index.php +++ b/index.php @@ -1,35 +1,49 @@ 'black', 'mario' => 'orange', 'luigi' => 'brown']; + //echo $ninjasOne['mario']; + //print_r($ninjasOne); + + $ninjasTwo = array('bowser' => 'green', 'peach' => 'yellow'); + //print_r($ninjasTwo); + + $ninjasTwo['toad'] = 'pink'; + + //echo count($ninjasTwo); + + $ninjasThree = array_merge($ninjasOne, $ninjasTwo); + print_r($ninjasThree); - // number functions - echo floor($pi); - echo ceil($pi); - echo pi(); ?> @@ -40,7 +54,7 @@ -

+

\ No newline at end of file From 14240eed9e6ebd5e912a60baaf4d581bcd7f0ab3 Mon Sep 17 00:00:00 2001 From: Shaun Date: Wed, 9 Jan 2019 18:53:18 +0000 Subject: [PATCH 06/38] lesson-8 --- index.php | 53 ++++++++++++++--------------------------------------- 1 file changed, 14 insertions(+), 39 deletions(-) diff --git a/index.php b/index.php index 3dedffd..6424d8e 100644 --- a/index.php +++ b/index.php @@ -1,48 +1,23 @@ 'mario party', 'author' => 'mario', 'content' => 'lorem'], + ['title' => 'mariokart cheats', 'author' => 'toad', 'content' => 'lorem'], + ['title' => 'zelda hidden chests', 'author' => 'link', 'content' => 'lorem'] + ]; - $peopleTwo = array('ken', 'chun-li'); - //echo $peopleTwo[1]; + //print_r($blogs); + //print_r($blogs[2]); + //echo $blogs[1]['title']; + //echo count($blogs); - $ages = [20, 30, 40, 50]; - - //print_r($ages); - - $ages[1] = 25; - //print_r($ages); - - $ages[] = 10; - array_push($ages, 70); - //print_r($ages); - - //echo array_pop($ages); - //print_r($ages); - - //echo count($ages); - - $peopleThree = array_merge($peopleOne, $peopleTwo); - //print_r($peopleThree); - - // associative array (key & value pairs) - - $ninjasOne = ['shaun' => 'black', 'mario' => 'orange', 'luigi' => 'brown']; - //echo $ninjasOne['mario']; - //print_r($ninjasOne); - - $ninjasTwo = array('bowser' => 'green', 'peach' => 'yellow'); - //print_r($ninjasTwo); - - $ninjasTwo['toad'] = 'pink'; - - //echo count($ninjasTwo); - - $ninjasThree = array_merge($ninjasOne, $ninjasTwo); - print_r($ninjasThree); + $blogs[] = ['title' => 'castle party', 'author' => 'peach', 'content' => 'lorem']; + //print_r($blogs); + $popped = array_pop($blogs); + //print_r($popped); ?> From b6feeb3b5f3333612dde21c67b1370d8628bd624 Mon Sep 17 00:00:00 2001 From: Shaun Date: Wed, 9 Jan 2019 19:42:01 +0000 Subject: [PATCH 07/38] lesson-9 --- index.php | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/index.php b/index.php index 6424d8e..efc7df7 100644 --- a/index.php +++ b/index.php @@ -1,23 +1,36 @@ 'mario party', 'author' => 'mario', 'content' => 'lorem'], - ['title' => 'mariokart cheats', 'author' => 'toad', 'content' => 'lorem'], - ['title' => 'zelda hidden chests', 'author' => 'link', 'content' => 'lorem'] + $ninjas = ['shaun', 'ryu', 'yoshi']; + + // for($i = 0; $i < count($ninjas); $i++){ + // echo $ninjas[$i] . '
'; + // } + + // foreach($ninjas as $ninja){ + // echo $ninja . '
'; + // } + + $products = [ + ['name' => 'shiny star', 'price' => 20], + ['name' => 'green shell', 'price' => 10], + ['name' => 'red shell', 'price' => 15], + ['name' => 'gold coin', 'price' => 5], + ['name' => 'lightning bolt', 'price' => 40], + ['name' => 'banana skin', 'price' => 2] ]; - //print_r($blogs); - //print_r($blogs[2]); - //echo $blogs[1]['title']; - //echo count($blogs); + // foreach($products as $product){ + // echo $product['name'] .' - '. $product['price']; + // echo '
'; + // } - $blogs[] = ['title' => 'castle party', 'author' => 'peach', 'content' => 'lorem']; - //print_r($blogs); + $i = 0; - $popped = array_pop($blogs); - //print_r($popped); + while($i < count($products)){ + echo $products[$i]['name']; + echo '
'; + $i++; + } ?> @@ -29,7 +42,13 @@ -

+

Products

+
    + +

    +

    £

    + +
\ No newline at end of file From 732e39439ddca1d7fbdc19f4792ec457c9217f98 Mon Sep 17 00:00:00 2001 From: Shaun Date: Thu, 10 Jan 2019 11:29:29 +0000 Subject: [PATCH 08/38] lesson-10 --- index.php | 70 +++++++++++++++++++++++-------------------------------- 1 file changed, 29 insertions(+), 41 deletions(-) diff --git a/index.php b/index.php index efc7df7..5914bf0 100644 --- a/index.php +++ b/index.php @@ -1,38 +1,34 @@ '; - // } - - // foreach($ninjas as $ninja){ - // echo $ninja . '
'; - // } - - $products = [ - ['name' => 'shiny star', 'price' => 20], - ['name' => 'green shell', 'price' => 10], - ['name' => 'red shell', 'price' => 15], - ['name' => 'gold coin', 'price' => 5], - ['name' => 'lightning bolt', 'price' => 40], - ['name' => 'banana skin', 'price' => 2] - ]; - - // foreach($products as $product){ - // echo $product['name'] .' - '. $product['price']; - // echo '
'; - // } - - $i = 0; - - while($i < count($products)){ - echo $products[$i]['name']; - echo '
'; - $i++; - } - - + // comparisons & booleans (true or false) + //echo true // echo's "1" + //echo false // echo's "" + + // numbers + //echo 5 < 10; + //echo 5 > 10; + //echo 5 == 10; + //echo 10 == 10; + //echo 5 != 10; + //echo 5 <= 5; + //echo 5 >= 5; + + // strings + //echo 'shaun' < 'yoshi'; + //echo 'shaun' > 'yoshi'; + //echo 'shaun' > 'Shaun'; + //echo 'mario' == 'mario'; + //echo 'mario' == 'Mario'; + + // loose vs strict equal comparison + + //echo 5 == '5'; + //echo 5 === '5'; + //echo 5 === 5; + + //echo true == 1; + echo true === 1; + ?> @@ -42,13 +38,5 @@ -

Products

-
    - -

    -

    £

    - -
- \ No newline at end of file From 52b9a0adc587dd41c268a052460a6f20d7460860 Mon Sep 17 00:00:00 2001 From: Shaun Date: Thu, 10 Jan 2019 11:54:56 +0000 Subject: [PATCH 09/38] lesson-11 --- index.php | 70 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 28 deletions(-) diff --git a/index.php b/index.php index 5914bf0..886c315 100644 --- a/index.php +++ b/index.php @@ -1,34 +1,38 @@ 10; - //echo 5 == 10; - //echo 10 == 10; - //echo 5 != 10; - //echo 5 <= 5; - //echo 5 >= 5; - - // strings - //echo 'shaun' < 'yoshi'; - //echo 'shaun' > 'yoshi'; - //echo 'shaun' > 'Shaun'; - //echo 'mario' == 'mario'; - //echo 'mario' == 'Mario'; - - // loose vs strict equal comparison - - //echo 5 == '5'; - //echo 5 === '5'; - //echo 5 === 5; - - //echo true == 1; - echo true === 1; + // conditional statements + // $price = 20; + + // if($price < 30){ + // echo 'if condition met'; + // } elseif($price === 20) { + // echo 'elseif condition met'; + // } else { + // echo 'condition not met'; + // } + + $products = [ + ['name' => 'shiny star', 'price' => 20], + ['name' => 'green shell', 'price' => 10], + ['name' => 'red shell', 'price' => 15], + ['name' => 'gold coin', 'price' => 5], + ['name' => 'lightning bolt', 'price' => 40], + ['name' => 'banana skin', 'price' => 2] + ]; + + foreach($products as $product){ + + // if($product['price'] < 15 && $product['price'] > 2){ + // echo $product['name'] . '
'; + // } + + // if($product['price'] > 20 || $product['price'] < 10){ + // echo $product['name'] . '
'; + // } + + } + ?> @@ -38,5 +42,15 @@ +
+
    + + 15){ ?> +
  • + + +
+
+ \ No newline at end of file From 3f40571625d6089c08bdde1086dd3f5f5be7fd24 Mon Sep 17 00:00:00 2001 From: Shaun Date: Thu, 10 Jan 2019 12:00:22 +0000 Subject: [PATCH 10/38] lesson-12 --- index.php | 36 +++++++++--------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/index.php b/index.php index 886c315..69bb2f6 100644 --- a/index.php +++ b/index.php @@ -1,17 +1,7 @@ 'shiny star', 'price' => 20], ['name' => 'green shell', 'price' => 10], @@ -23,13 +13,15 @@ foreach($products as $product){ - // if($product['price'] < 15 && $product['price'] > 2){ - // echo $product['name'] . '
'; - // } + if($product['name'] === 'lightning bolt'){ + break; + } - // if($product['price'] > 20 || $product['price'] < 10){ - // echo $product['name'] . '
'; - // } + if($product['price'] > 15){ + continue; + } + + echo $product['name'] . '
'; } @@ -42,15 +34,5 @@ -
-
    - - 15){ ?> -
  • - - -
-
- \ No newline at end of file From 04809c78d2354de4f4bc69f5b22a5cb2f5b79a29 Mon Sep 17 00:00:00 2001 From: Shaun Date: Thu, 10 Jan 2019 12:38:28 +0000 Subject: [PATCH 11/38] lesson-13 --- index.php | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/index.php b/index.php index 69bb2f6..665e60e 100644 --- a/index.php +++ b/index.php @@ -1,29 +1,24 @@ 'shiny star', 'price' => 20], - ['name' => 'green shell', 'price' => 10], - ['name' => 'red shell', 'price' => 15], - ['name' => 'gold coin', 'price' => 5], - ['name' => 'lightning bolt', 'price' => 40], - ['name' => 'banana skin', 'price' => 2] - ]; - - foreach($products as $product){ - - if($product['name'] === 'lightning bolt'){ - break; - } + // functions - if($product['price'] > 15){ - continue; - } + function sayHello($name = 'shaun', $time = 'morning'){ + echo "Good $time, $name"; + } - echo $product['name'] . '
'; + //sayHello(); + //sayHello('mario'); + sayHello('yoshi', 'night'); + function formatProduct($product){ + // echo "{$product['name']} costs £{$product['price']} to buy
"; + return "The {$product['name']} costs £{$product['price']} to buy
"; } + + //formatProduct(['name' => 'gold star', 'price' => 20]); + + // $formatted = formatProduct(['name' => 'gold star', 'price' => 20]); + // echo $formatted; ?> From 534c3ec1c62a4f14c340581847fa0afadb78cd03 Mon Sep 17 00:00:00 2001 From: Shaun Date: Thu, 10 Jan 2019 13:21:26 +0000 Subject: [PATCH 12/38] lesson-14 --- index.php | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/index.php b/index.php index 665e60e..959e56c 100644 --- a/index.php +++ b/index.php @@ -1,24 +1,45 @@ "; - return "The {$product['name']} costs £{$product['price']} to buy
"; + function myFuncTwo($age){ + echo $age; } - - //formatProduct(['name' => 'gold star', 'price' => 20]); - // $formatted = formatProduct(['name' => 'gold star', 'price' => 20]); - // echo $formatted; + // myFuncTwo(25); + // echo $age; + + // global variables + + $name = 'mario'; + + // function sayHello(){ + // global $name; + // $name = 'yoshi'; + // echo "hello $name "; + // } + + // sayHello(); + // echo $name; + + function sayBye(&$name){ + $name = 'wario'; + echo "bye $name "; + } + + sayBye($name); + echo $name; + ?> From e7862331ea326698b3265ae2bc203c67ca37d434 Mon Sep 17 00:00:00 2001 From: Shaun Date: Thu, 10 Jan 2019 14:27:18 +0000 Subject: [PATCH 13/38] lesson-15 --- content.php | 3 +++ index.php | 46 +++++++++------------------------------------- ninjas.php | 7 +++++++ 3 files changed, 19 insertions(+), 37 deletions(-) create mode 100644 content.php create mode 100644 ninjas.php diff --git a/content.php b/content.php new file mode 100644 index 0000000..9f13b4b --- /dev/null +++ b/content.php @@ -0,0 +1,3 @@ +
+

+
\ No newline at end of file diff --git a/index.php b/index.php index 959e56c..9b01618 100644 --- a/index.php +++ b/index.php @@ -1,45 +1,14 @@ @@ -50,5 +19,8 @@ function sayBye(&$name){ + + + \ No newline at end of file diff --git a/ninjas.php b/ninjas.php new file mode 100644 index 0000000..c9255ee --- /dev/null +++ b/ninjas.php @@ -0,0 +1,7 @@ +'; + +?> \ No newline at end of file From 571496c4fe24770aa3a662dc4db0df6e5701e87f Mon Sep 17 00:00:00 2001 From: Shaun Date: Thu, 10 Jan 2019 15:37:57 +0000 Subject: [PATCH 14/38] lesson-16 --- content.php | 3 --- index.php | 19 +++---------------- ninjas.php | 7 ------- templates/footer.php | 5 +++++ templates/header.php | 22 ++++++++++++++++++++++ 5 files changed, 30 insertions(+), 26 deletions(-) delete mode 100644 content.php delete mode 100644 ninjas.php create mode 100644 templates/footer.php create mode 100644 templates/header.php diff --git a/content.php b/content.php deleted file mode 100644 index 9f13b4b..0000000 --- a/content.php +++ /dev/null @@ -1,3 +0,0 @@ -
-

-
\ No newline at end of file diff --git a/index.php b/index.php index 9b01618..6340b31 100644 --- a/index.php +++ b/index.php @@ -1,26 +1,13 @@ - - PHP Tutorials - - + + - - + - \ No newline at end of file diff --git a/ninjas.php b/ninjas.php deleted file mode 100644 index c9255ee..0000000 --- a/ninjas.php +++ /dev/null @@ -1,7 +0,0 @@ -'; - -?> \ No newline at end of file diff --git a/templates/footer.php b/templates/footer.php new file mode 100644 index 0000000..c96829e --- /dev/null +++ b/templates/footer.php @@ -0,0 +1,5 @@ + +
+
© Copyright 2019 Ninja Pizzas
+
+ \ No newline at end of file diff --git a/templates/header.php b/templates/header.php new file mode 100644 index 0000000..928355d --- /dev/null +++ b/templates/header.php @@ -0,0 +1,22 @@ + + Ninja Pizza + + + + + + From e6f95a0dca0d00acbd4318c6e101c7a9bc39b73a Mon Sep 17 00:00:00 2001 From: Shaun Date: Thu, 10 Jan 2019 16:14:27 +0000 Subject: [PATCH 15/38] lesson-17 --- add.php | 39 +++++++++++++++++++++++++++++++++++++++ index.php | 1 - templates/header.php | 5 +++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 add.php diff --git a/add.php b/add.php new file mode 100644 index 0000000..676e006 --- /dev/null +++ b/add.php @@ -0,0 +1,39 @@ +'; + // echo $_GET['title'] . '
'; + // echo $_GET['ingredients'] . '
'; + // } + + if(isset($_POST['submit'])){ + echo $_POST['email'] . '
'; + echo $_POST['title'] . '
'; + echo $_POST['ingredients'] . '
'; + } + +?> + + + + + + +
+

Add a Pizza

+
+ + + + + + +
+ +
+
+
+ + + + \ No newline at end of file diff --git a/index.php b/index.php index 6340b31..251d03a 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,5 @@ diff --git a/templates/header.php b/templates/header.php index 928355d..a963a5a 100644 --- a/templates/header.php +++ b/templates/header.php @@ -9,6 +9,11 @@ .brand-text{ color: #cbb09c !important; } + form{ + max-width: 460px; + margin: 20px auto; + padding: 20px; + } From 54464459fdedee95f5a6063e369a03f07ea03304 Mon Sep 17 00:00:00 2001 From: Shaun Date: Thu, 10 Jan 2019 16:20:48 +0000 Subject: [PATCH 16/38] lesson-18 --- add.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/add.php b/add.php index 676e006..109ecd3 100644 --- a/add.php +++ b/add.php @@ -7,9 +7,9 @@ // } if(isset($_POST['submit'])){ - echo $_POST['email'] . '
'; - echo $_POST['title'] . '
'; - echo $_POST['ingredients'] . '
'; + echo htmlspecialchars($_POST['email']) . '
'; + echo htmlspecialchars($_POST['title']) . '
'; + echo htmlspecialchars($_POST['ingredients']) . '
'; } ?> From a503937a8e4b0ccc4483fcec14a13569e3972e72 Mon Sep 17 00:00:00 2001 From: Shaun Date: Thu, 10 Jan 2019 16:34:29 +0000 Subject: [PATCH 17/38] lesson-19 --- add.php | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/add.php b/add.php index 109ecd3..8cd9f11 100644 --- a/add.php +++ b/add.php @@ -1,16 +1,29 @@ '; - // echo $_GET['title'] . '
'; - // echo $_GET['ingredients'] . '
'; - // } - if(isset($_POST['submit'])){ - echo htmlspecialchars($_POST['email']) . '
'; - echo htmlspecialchars($_POST['title']) . '
'; - echo htmlspecialchars($_POST['ingredients']) . '
'; - } + + // check email + if(empty($_POST['email'])){ + echo 'An email is required
'; + } else{ + echo htmlspecialchars($_POST['email']) . '
'; + } + + // check title + if(empty($_POST['title'])){ + echo 'A title is required
'; + } else{ + echo htmlspecialchars($_POST['title']) . '
'; + } + + // check ingredients + if(empty($_POST['ingredients'])){ + echo 'At least one ingredient is required
'; + } else{ + echo htmlspecialchars($_POST['ingredients']) . '
'; + } + + } // end POST check ?> From 8d768bd3ef08d415c82411fe0ad358b4a35f17b2 Mon Sep 17 00:00:00 2001 From: Shaun Date: Thu, 10 Jan 2019 17:08:58 +0000 Subject: [PATCH 18/38] lesson-20 --- add.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/add.php b/add.php index 8cd9f11..74a0853 100644 --- a/add.php +++ b/add.php @@ -1,26 +1,37 @@ '; } else{ - echo htmlspecialchars($_POST['email']) . '
'; + $email = $_POST['email']; + if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ + echo 'Email must be a valid email address'; + } } // check title if(empty($_POST['title'])){ echo 'A title is required
'; } else{ - echo htmlspecialchars($_POST['title']) . '
'; + $title = $_POST['title']; + if(!preg_match('/^[a-zA-Z\s]+$/', $title)){ + echo 'Title must be letters and spaces only'; + } } // check ingredients if(empty($_POST['ingredients'])){ echo 'At least one ingredient is required
'; } else{ - echo htmlspecialchars($_POST['ingredients']) . '
'; + $ingredients = $_POST['ingredients']; + if(!preg_match('/^([a-zA-Z\s]+)(,\s*[a-zA-Z\s]*)*$/', $ingredients)){ + echo 'Ingredients must be a comma separated list'; + } } } // end POST check From ebe762eff803975a5f8c00bba14d0df37c8fdbfa Mon Sep 17 00:00:00 2001 From: Shaun Date: Fri, 11 Jan 2019 10:35:31 +0000 Subject: [PATCH 19/38] lesson-21 --- add.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/add.php b/add.php index 74a0853..e97c4f9 100644 --- a/add.php +++ b/add.php @@ -1,36 +1,37 @@ '', 'title' => '', 'ingredients' => ''); - $email = $title = $ingredients = ''; + if(isset($_POST['submit'])){ // check email if(empty($_POST['email'])){ - echo 'An email is required
'; + $errors['email'] = 'An email is required'; } else{ $email = $_POST['email']; if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ - echo 'Email must be a valid email address'; + $errors['email'] = 'Email must be a valid email address'; } } // check title if(empty($_POST['title'])){ - echo 'A title is required
'; + $errors['title'] = 'A title is required'; } else{ $title = $_POST['title']; if(!preg_match('/^[a-zA-Z\s]+$/', $title)){ - echo 'Title must be letters and spaces only'; + $errors['title'] = 'Title must be letters and spaces only'; } } // check ingredients if(empty($_POST['ingredients'])){ - echo 'At least one ingredient is required
'; + $errors['ingredients'] = 'At least one ingredient is required'; } else{ $ingredients = $_POST['ingredients']; if(!preg_match('/^([a-zA-Z\s]+)(,\s*[a-zA-Z\s]*)*$/', $ingredients)){ - echo 'Ingredients must be a comma separated list'; + $errors['ingredients'] = 'Ingredients must be a comma separated list'; } } @@ -47,11 +48,14 @@

Add a Pizza

- + +
- + +
- + +
From 1cf6e938d21029d6cd9f7f693536d47cd40360bf Mon Sep 17 00:00:00 2001 From: Shaun Date: Fri, 11 Jan 2019 10:37:20 +0000 Subject: [PATCH 20/38] lesson-22 --- add.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/add.php b/add.php index e97c4f9..65b155a 100644 --- a/add.php +++ b/add.php @@ -35,6 +35,13 @@ } } + if(array_filter($errors)){ + //echo 'errors in form'; + } else { + //echo 'form is valid'; + header('Location: index.php'); + } + } // end POST check ?> From d336b54351878d6283db6d93c94439eaeab3267f Mon Sep 17 00:00:00 2001 From: Shaun Date: Fri, 11 Jan 2019 11:16:00 +0000 Subject: [PATCH 21/38] lesson-26 --- index.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/index.php b/index.php index 251d03a..bde0737 100644 --- a/index.php +++ b/index.php @@ -1,5 +1,31 @@ From 382f8b29dbd981208682a115ea9e933dc1d272ce Mon Sep 17 00:00:00 2001 From: Shaun Date: Fri, 11 Jan 2019 12:06:31 +0000 Subject: [PATCH 22/38] lesson-27 --- index.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index bde0737..c74122f 100644 --- a/index.php +++ b/index.php @@ -23,8 +23,6 @@ // close connection mysqli_close($conn); - print_r($pizzas); - ?> @@ -33,6 +31,30 @@ +

Pizzas!

+ +
+
+ + + +
+
+
+
+
+
+
+ more info +
+
+
+ + + +
+
+ \ No newline at end of file From f6ba2528127a4db8c7f477c3d790048989be40b5 Mon Sep 17 00:00:00 2001 From: Shaun Date: Fri, 11 Jan 2019 12:11:13 +0000 Subject: [PATCH 23/38] lesson-28 --- index.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index c74122f..3d1be88 100644 --- a/index.php +++ b/index.php @@ -23,6 +23,8 @@ // close connection mysqli_close($conn); + //print_r(explode(',', $pizzas[0]['ingredients'])); + ?> @@ -42,7 +44,11 @@
-
+
    + +
  • + +
more info From 53acc3bceb80334b4b04be8849288348dd81db8c Mon Sep 17 00:00:00 2001 From: Shaun Date: Fri, 11 Jan 2019 12:17:34 +0000 Subject: [PATCH 24/38] lesson-29 --- index.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/index.php b/index.php index 3d1be88..17a0219 100644 --- a/index.php +++ b/index.php @@ -23,8 +23,6 @@ // close connection mysqli_close($conn); - //print_r(explode(',', $pizzas[0]['ingredients'])); - ?> @@ -38,16 +36,16 @@
- +
    - +
  • - +
@@ -56,7 +54,13 @@
- + + + = 3): ?> +

There is more than 3 pizza

+ +

There are fewer than 3 pizzas

+
From 2f1c366d53444ca03126b577571884e8499e09c6 Mon Sep 17 00:00:00 2001 From: Shaun Date: Fri, 11 Jan 2019 12:29:20 +0000 Subject: [PATCH 25/38] lesson-30 --- add.php | 23 ++++++++++++++++++++--- config/db_connect.php | 11 +++++++++++ index.php | 16 ++-------------- 3 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 config/db_connect.php diff --git a/add.php b/add.php index 65b155a..f9e2308 100644 --- a/add.php +++ b/add.php @@ -1,4 +1,6 @@ - '', 'title' => '', 'ingredients' => ''); @@ -38,8 +40,23 @@ if(array_filter($errors)){ //echo 'errors in form'; } else { - //echo 'form is valid'; - header('Location: index.php'); + // escape sql chars + $email = mysqli_real_escape_string($conn, $_POST['email']); + $title = mysqli_real_escape_string($conn, $_POST['title']); + $ingredients = mysqli_real_escape_string($conn, $_POST['ingredients']); + + // create sql + $sql = "INSERT INTO pizzas(title,email,ingredients) VALUES('$title','$email','$ingredients')"; + + // save to db and check + if(mysqli_query($conn, $sql)){ + // success + header('Location: index.php'); + } else { + echo 'query error: '. mysqli_error($conn); + } + + } } // end POST check diff --git a/config/db_connect.php b/config/db_connect.php new file mode 100644 index 0000000..7ef73e1 --- /dev/null +++ b/config/db_connect.php @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/index.php b/index.php index 17a0219..78be590 100644 --- a/index.php +++ b/index.php @@ -1,12 +1,6 @@ -
+
@@ -56,12 +50,6 @@ - = 3): ?> -

There is more than 3 pizza

- -

There are fewer than 3 pizzas

- -
From ebb3507615913b4aa926d749334736681e60fd45 Mon Sep 17 00:00:00 2001 From: Shaun Date: Fri, 11 Jan 2019 12:58:59 +0000 Subject: [PATCH 26/38] lesson-31 --- add.php | 1 - details.php | 46 ++++++++++++++++++++++++++++++++++++++++++++ index.php | 2 +- templates/header.php | 4 ++-- 4 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 details.php diff --git a/add.php b/add.php index f9e2308..7e1c704 100644 --- a/add.php +++ b/add.php @@ -55,7 +55,6 @@ } else { echo 'query error: '. mysqli_error($conn); } - } diff --git a/details.php b/details.php new file mode 100644 index 0000000..50b1be4 --- /dev/null +++ b/details.php @@ -0,0 +1,46 @@ + + + + + + + +
+ +

+

Created by

+

+
Ingredients:
+

+ +
No such pizza exists.
+ +
+ + + + \ No newline at end of file diff --git a/index.php b/index.php index 78be590..25ccd57 100644 --- a/index.php +++ b/index.php @@ -43,7 +43,7 @@
diff --git a/templates/header.php b/templates/header.php index a963a5a..b6be828 100644 --- a/templates/header.php +++ b/templates/header.php @@ -19,9 +19,9 @@ From d9942afb96964aedc61f1ae9bdd5bfe66472f83f Mon Sep 17 00:00:00 2001 From: Shaun Date: Fri, 11 Jan 2019 13:16:46 +0000 Subject: [PATCH 27/38] lesson-32 --- details.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/details.php b/details.php index 50b1be4..88dcbbb 100644 --- a/details.php +++ b/details.php @@ -2,6 +2,20 @@ include('config/db_connect.php'); + if(isset($_POST['delete'])){ + + $id_to_delete = mysqli_real_escape_string($conn, $_POST['id_to_delete']); + + $sql = "DELETE FROM pizzas WHERE id = $id_to_delete"; + + if(mysqli_query($conn, $sql)){ + header('Location: index.php'); + } else { + echo 'query error: '. mysqli_error($conn); + } + + } + // check GET request id param if(isset($_GET['id'])){ @@ -36,6 +50,13 @@

Ingredients:

+ + + + + + +
No such pizza exists.
From fedac146dac085dfe3cb34a075abdcb1d16e13e5 Mon Sep 17 00:00:00 2001 From: Shaun Date: Fri, 11 Jan 2019 14:09:11 +0000 Subject: [PATCH 28/38] lesson-33 --- details.php | 2 +- img/pizza.svg | 111 +++++++++++++++++++++++++++++++++++++++++++ index.php | 1 + templates/header.php | 7 +++ 4 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 img/pizza.svg diff --git a/details.php b/details.php index 88dcbbb..9fc6cc4 100644 --- a/details.php +++ b/details.php @@ -43,7 +43,7 @@ -
+

Created by

diff --git a/img/pizza.svg b/img/pizza.svg new file mode 100644 index 0000000..fd3920d --- /dev/null +++ b/img/pizza.svg @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/index.php b/index.php index 25ccd57..0cc0158 100644 --- a/index.php +++ b/index.php @@ -34,6 +34,7 @@
+
    diff --git a/templates/header.php b/templates/header.php index b6be828..0f436da 100644 --- a/templates/header.php +++ b/templates/header.php @@ -14,6 +14,13 @@ margin: 20px auto; padding: 20px; } + .pizza{ + width: 100px; + margin: 40px auto -30px; + display: block; + position: relative; + top: -30px; + } From be3a02a5216f16702652b58c4218cb38797a13f5 Mon Sep 17 00:00:00 2001 From: Shaun Date: Fri, 11 Jan 2019 16:02:31 +0000 Subject: [PATCH 29/38] lesson-34 --- add.php | 2 +- sandbox.php | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 sandbox.php diff --git a/add.php b/add.php index 7e1c704..f242585 100644 --- a/add.php +++ b/add.php @@ -55,7 +55,7 @@ } else { echo 'query error: '. mysqli_error($conn); } - + } } // end POST check diff --git a/sandbox.php b/sandbox.php new file mode 100644 index 0000000..d508790 --- /dev/null +++ b/sandbox.php @@ -0,0 +1,27 @@ + 40){ + // echo 'high score!'; + // } else { + // echo 'low score!'; + // } + + // echo $score > 40 ? 'high score!' : 'low score!'; + +?> + + + + + php tuts + + + +

    40 ? 'high score!' : 'low score!'; ?>

    + + + \ No newline at end of file From c6f4ee6832f25f90885cc82e4aa56ba7a33083ee Mon Sep 17 00:00:00 2001 From: Shaun Date: Fri, 11 Jan 2019 16:35:45 +0000 Subject: [PATCH 30/38] lesson-35 --- add.php | 2 +- sandbox.php | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/add.php b/add.php index f242585..a7e1db2 100644 --- a/add.php +++ b/add.php @@ -69,7 +69,7 @@

    Add a Pizza

    -
    +
    diff --git a/sandbox.php b/sandbox.php index d508790..aa0fadd 100644 --- a/sandbox.php +++ b/sandbox.php @@ -1,16 +1,16 @@ 40){ - // echo 'high score!'; - // } else { - // echo 'low score!'; - // } + echo $_SERVER['SERVER_NAME'] . '
    '; + echo $_SERVER['REQUEST_METHOD'] . '
    '; + echo $_SERVER['SCRIPT_FILENAME'] . '
    '; + echo $_SERVER['PHP_SELF'] . '
    '; + + // $_COOKIE, $_SESSION - // echo $score > 40 ? 'high score!' : 'low score!'; ?> @@ -21,7 +21,5 @@ -

    40 ? 'high score!' : 'low score!'; ?>

    - \ No newline at end of file From 7a4aa1fe796da4b34fa19db5bf95957fdb90d20b Mon Sep 17 00:00:00 2001 From: Shaun Date: Fri, 11 Jan 2019 17:03:42 +0000 Subject: [PATCH 31/38] lesson-36 --- add.php | 2 +- index.php | 2 +- sandbox.php | 18 ++++++++++-------- templates/header.php | 16 ++++++++++++++++ 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/add.php b/add.php index a7e1db2..d55c8b5 100644 --- a/add.php +++ b/add.php @@ -69,7 +69,7 @@

    Add a Pizza

    - +
    diff --git a/index.php b/index.php index 0cc0158..3368861 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,4 @@ -'; - echo $_SERVER['REQUEST_METHOD'] . '
    '; - echo $_SERVER['SCRIPT_FILENAME'] . '
    '; - echo $_SERVER['PHP_SELF'] . '
    '; - - // $_COOKIE, $_SESSION + $_SESSION['name'] = $_POST['name']; + header('Location: index.php'); + } ?> @@ -21,5 +18,10 @@ + + + + + \ No newline at end of file diff --git a/templates/header.php b/templates/header.php index 0f436da..747e36f 100644 --- a/templates/header.php +++ b/templates/header.php @@ -1,3 +1,18 @@ + + Ninja Pizza @@ -28,6 +43,7 @@ From e21e03a82c8386d72b5a1e05b6e4789876c8beb0 Mon Sep 17 00:00:00 2001 From: Shaun Date: Fri, 11 Jan 2019 17:17:49 +0000 Subject: [PATCH 32/38] lesson-37 --- templates/header.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/header.php b/templates/header.php index 747e36f..93d7690 100644 --- a/templates/header.php +++ b/templates/header.php @@ -9,7 +9,7 @@ session_unset(); } - $name = htmlspecialchars($_SESSION['name']); + $name = $_SESSION['name'] ?? 'Guest'; ?> From 0a2c49f86d291115ca011054540a622662a7fdd3 Mon Sep 17 00:00:00 2001 From: Shaun Date: Fri, 11 Jan 2019 17:29:23 +0000 Subject: [PATCH 33/38] lesson-37 --- sandbox.php | 8 ++++++++ templates/header.php | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/sandbox.php b/sandbox.php index 7f1ca71..5b89c9a 100644 --- a/sandbox.php +++ b/sandbox.php @@ -9,6 +9,14 @@ header('Location: index.php'); } + // spaceship operator + //$result = 5 <=> 6; + //$result = 5 <=> 4; + //$result = 5 <=> 5; + $result = 'shaun' <=> 'yoshi'; + + echo $result; + ?> diff --git a/templates/header.php b/templates/header.php index 93d7690..460cf6e 100644 --- a/templates/header.php +++ b/templates/header.php @@ -9,6 +9,7 @@ session_unset(); } + // null coalesce $name = $_SESSION['name'] ?? 'Guest'; ?> @@ -43,7 +44,7 @@
    From f15153d7ff604c020d08cf0dde99f1d05575e92e Mon Sep 17 00:00:00 2001 From: Shaun Date: Fri, 11 Jan 2019 20:17:51 +0000 Subject: [PATCH 34/38] lesson-38 --- index.php | 1 - sandbox.php | 15 +++++++-------- templates/header.php | 4 ++++ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/index.php b/index.php index 3368861..09a244b 100644 --- a/index.php +++ b/index.php @@ -17,7 +17,6 @@ // close connection mysqli_close($conn); - ?> diff --git a/sandbox.php b/sandbox.php index 5b89c9a..b41aa48 100644 --- a/sandbox.php +++ b/sandbox.php @@ -2,6 +2,9 @@ if(isset($_POST['submit'])){ + //cookie for gender + setcookie('gender', $_POST['gender'], time() + 86400); + session_start(); $_SESSION['name'] = $_POST['name']; @@ -9,14 +12,6 @@ header('Location: index.php'); } - // spaceship operator - //$result = 5 <=> 6; - //$result = 5 <=> 4; - //$result = 5 <=> 5; - $result = 'shaun' <=> 'yoshi'; - - echo $result; - ?> @@ -28,6 +23,10 @@
    +
    diff --git a/templates/header.php b/templates/header.php index 460cf6e..b6216a4 100644 --- a/templates/header.php +++ b/templates/header.php @@ -12,6 +12,9 @@ // null coalesce $name = $_SESSION['name'] ?? 'Guest'; + // get cookie + $gender = $_COOKIE['gender'] ?? 'Unknown'; + ?> @@ -45,6 +48,7 @@
From 1cbf5bfdaf530d11d9db919456f1259ea9d656a6 Mon Sep 17 00:00:00 2001 From: Shaun Date: Mon, 14 Jan 2019 12:31:21 +0000 Subject: [PATCH 35/38] lesson-39 --- add.php | 90 ---------------------------------- config/db_connect.php | 11 ----- details.php | 67 ------------------------- img/pizza.svg | 111 ------------------------------------------ index.php | 58 ---------------------- quotes.txt | 6 +++ readme.txt | 6 +++ sandbox.php | 50 +++++++++---------- templates/footer.php | 5 -- templates/header.php | 55 --------------------- 10 files changed, 37 insertions(+), 422 deletions(-) delete mode 100644 add.php delete mode 100644 config/db_connect.php delete mode 100644 details.php delete mode 100644 img/pizza.svg delete mode 100644 index.php create mode 100644 quotes.txt create mode 100644 readme.txt delete mode 100644 templates/footer.php delete mode 100644 templates/header.php diff --git a/add.php b/add.php deleted file mode 100644 index d55c8b5..0000000 --- a/add.php +++ /dev/null @@ -1,90 +0,0 @@ - '', 'title' => '', 'ingredients' => ''); - - if(isset($_POST['submit'])){ - - // check email - if(empty($_POST['email'])){ - $errors['email'] = 'An email is required'; - } else{ - $email = $_POST['email']; - if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ - $errors['email'] = 'Email must be a valid email address'; - } - } - - // check title - if(empty($_POST['title'])){ - $errors['title'] = 'A title is required'; - } else{ - $title = $_POST['title']; - if(!preg_match('/^[a-zA-Z\s]+$/', $title)){ - $errors['title'] = 'Title must be letters and spaces only'; - } - } - - // check ingredients - if(empty($_POST['ingredients'])){ - $errors['ingredients'] = 'At least one ingredient is required'; - } else{ - $ingredients = $_POST['ingredients']; - if(!preg_match('/^([a-zA-Z\s]+)(,\s*[a-zA-Z\s]*)*$/', $ingredients)){ - $errors['ingredients'] = 'Ingredients must be a comma separated list'; - } - } - - if(array_filter($errors)){ - //echo 'errors in form'; - } else { - // escape sql chars - $email = mysqli_real_escape_string($conn, $_POST['email']); - $title = mysqli_real_escape_string($conn, $_POST['title']); - $ingredients = mysqli_real_escape_string($conn, $_POST['ingredients']); - - // create sql - $sql = "INSERT INTO pizzas(title,email,ingredients) VALUES('$title','$email','$ingredients')"; - - // save to db and check - if(mysqli_query($conn, $sql)){ - // success - header('Location: index.php'); - } else { - echo 'query error: '. mysqli_error($conn); - } - - } - - } // end POST check - -?> - - - - - - -
-

Add a Pizza

-
- - -
- - -
- - -
-
- -
-
-
- - - - \ No newline at end of file diff --git a/config/db_connect.php b/config/db_connect.php deleted file mode 100644 index 7ef73e1..0000000 --- a/config/db_connect.php +++ /dev/null @@ -1,11 +0,0 @@ - \ No newline at end of file diff --git a/details.php b/details.php deleted file mode 100644 index 9fc6cc4..0000000 --- a/details.php +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - -
- -

-

Created by

-

-
Ingredients:
-

- - -
- - -
- - -
No such pizza exists.
- -
- - - - \ No newline at end of file diff --git a/img/pizza.svg b/img/pizza.svg deleted file mode 100644 index fd3920d..0000000 --- a/img/pizza.svg +++ /dev/null @@ -1,111 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/index.php b/index.php deleted file mode 100644 index 09a244b..0000000 --- a/index.php +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - -

Pizzas!

- -
-
- - - -
-
- -
-
-
    - -
  • - -
-
-
- more info -
-
-
- - - -
-
- - - - \ No newline at end of file diff --git a/quotes.txt b/quotes.txt new file mode 100644 index 0000000..9faff73 --- /dev/null +++ b/quotes.txt @@ -0,0 +1,6 @@ +Be yourself; everyone else is already taken. +We are all in the gutter, but some of us are looking at the stars. +To live is the rarest thing in the world. Most people exist, that is all. +I can resist everything except temptation. +The truth is rarely pure and never simple. +Life is too important to be taken seriously. \ No newline at end of file diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..9faff73 --- /dev/null +++ b/readme.txt @@ -0,0 +1,6 @@ +Be yourself; everyone else is already taken. +We are all in the gutter, but some of us are looking at the stars. +To live is the rarest thing in the world. Most people exist, that is all. +I can resist everything except temptation. +The truth is rarely pure and never simple. +Life is too important to be taken seriously. \ No newline at end of file diff --git a/sandbox.php b/sandbox.php index b41aa48..6acdfa6 100644 --- a/sandbox.php +++ b/sandbox.php @@ -1,34 +1,34 @@ '; - $_SESSION['name'] = $_POST['name']; + // copy file + copy($file, 'quotes.txt'); - header('Location: index.php'); + // absolute path + echo realpath($file) . '
'; + + // file size + echo filesize($file) . '
'; + + // rename the file + rename($file, 'test.txt'); + + } else { + echo 'file does not exist'; } -?> + // make directory + mkdir('quotes'); - - - - php tuts - - - -
- - - -
- - - \ No newline at end of file + + +?> diff --git a/templates/footer.php b/templates/footer.php deleted file mode 100644 index c96829e..0000000 --- a/templates/footer.php +++ /dev/null @@ -1,5 +0,0 @@ - -
-
© Copyright 2019 Ninja Pizzas
-
- \ No newline at end of file diff --git a/templates/header.php b/templates/header.php deleted file mode 100644 index b6216a4..0000000 --- a/templates/header.php +++ /dev/null @@ -1,55 +0,0 @@ - - - - Ninja Pizza - - - - - - From 3a7bd2d54255f8f1950ce75666bbb4c960a6bf65 Mon Sep 17 00:00:00 2001 From: Shaun Date: Mon, 14 Jan 2019 15:59:18 +0000 Subject: [PATCH 36/38] lesson-40 --- readme.txt | 6 ------ sandbox.php | 44 ++++++++++++++++++++------------------------ 2 files changed, 20 insertions(+), 30 deletions(-) delete mode 100644 readme.txt diff --git a/readme.txt b/readme.txt deleted file mode 100644 index 9faff73..0000000 --- a/readme.txt +++ /dev/null @@ -1,6 +0,0 @@ -Be yourself; everyone else is already taken. -We are all in the gutter, but some of us are looking at the stars. -To live is the rarest thing in the world. Most people exist, that is all. -I can resist everything except temptation. -The truth is rarely pure and never simple. -Life is too important to be taken seriously. \ No newline at end of file diff --git a/sandbox.php b/sandbox.php index 6acdfa6..77e91c8 100644 --- a/sandbox.php +++ b/sandbox.php @@ -1,34 +1,30 @@ -'; - - // copy file - copy($file, 'quotes.txt'); + $file = 'quotes.txt'; + + // opening a file for reading + // $handle = fopen($file, 'r'); - // absolute path - echo realpath($file) . '
'; + // read the file + // echo fread($handle, filesize($file)); + // echo fread($handle, 112); - // file size - echo filesize($file) . '
'; + // read a single line + // echo fgets($handle); + // echo fgets($handle); - // rename the file - rename($file, 'test.txt'); + // read a single character + // echo fgetc($handle); + // echo fgetc($handle); - } else { - echo 'file does not exist'; - } + // $handle = fopen($file, 'r+'); + // $handle = fopen($file, 'a+'); - // make directory - mkdir('quotes'); + // writing to a file + // fwrite($handle, "\nEverything popular is wrong."); + // fclose($file); + unlink($file); ?> From cfe8023289e475c50e11c922e7087e7d510377d8 Mon Sep 17 00:00:00 2001 From: Shaun Date: Mon, 14 Jan 2019 16:54:13 +0000 Subject: [PATCH 37/38] lesson-41 --- quotes.txt | 6 ------ sandbox.php | 42 +++++++++++++++++++++++------------------- 2 files changed, 23 insertions(+), 25 deletions(-) delete mode 100644 quotes.txt diff --git a/quotes.txt b/quotes.txt deleted file mode 100644 index 9faff73..0000000 --- a/quotes.txt +++ /dev/null @@ -1,6 +0,0 @@ -Be yourself; everyone else is already taken. -We are all in the gutter, but some of us are looking at the stars. -To live is the rarest thing in the world. Most people exist, that is all. -I can resist everything except temptation. -The truth is rarely pure and never simple. -Life is too important to be taken seriously. \ No newline at end of file diff --git a/sandbox.php b/sandbox.php index 77e91c8..4a91dd4 100644 --- a/sandbox.php +++ b/sandbox.php @@ -1,30 +1,34 @@ name = 'mario'; + // $this->email = 'mario@thenetninja.co.uk'; + $this->name = $name; + $this->email = $email; + } - // read a single line - // echo fgets($handle); - // echo fgets($handle); + public function login(){ + // echo 'the user logged in'; + echo $this->name . ' logged in'; + } - // read a single character - // echo fgetc($handle); - // echo fgetc($handle); + } + + // $userOne = new User(); + + // $userOne->login(); + // echo $userOne->name; - // $handle = fopen($file, 'r+'); - // $handle = fopen($file, 'a+'); + $userTwo = new User('yoshi', 'yoshi@thenetninja.co.uk'); - // writing to a file - // fwrite($handle, "\nEverything popular is wrong."); + // echo $userTwo->email; + $userTwo->login(); - // fclose($file); - unlink($file); ?> From 1726838d22ca4509e758d6c4cdbef7eaa044ce84 Mon Sep 17 00:00:00 2001 From: Shaun Date: Mon, 14 Jan 2019 17:23:41 +0000 Subject: [PATCH 38/38] lesson-42 --- sandbox.php | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/sandbox.php b/sandbox.php index 4a91dd4..778284a 100644 --- a/sandbox.php +++ b/sandbox.php @@ -2,8 +2,8 @@ class User { - public $email; - public $name; + private $email; + private $name; public function __construct($name, $email){ // $this->name = 'mario'; @@ -17,18 +17,28 @@ public function login(){ echo $this->name . ' logged in'; } - } + public function getName(){ + return $this->name; + } + + public function setName($name){ + if(is_string($name) && strlen($name) > 1){ + $this->name = $name; + return "name updated to $name"; + } else { + return 'not a valid name'; + } + } - // $userOne = new User(); - - // $userOne->login(); - // echo $userOne->name; + } $userTwo = new User('yoshi', 'yoshi@thenetninja.co.uk'); - // echo $userTwo->email; - $userTwo->login(); - + // $userTwo->name = 'mario'; + // echo $userTwo->name; + // echo $userTwo->getName(); + // echo $userTwo->setName('shaun'); + // echo $userTwo->getName(); ?>