diff --git a/product_crud_0/.DS_Store b/product_crud_0/.DS_Store
index b159947..b18eecb 100644
Binary files a/product_crud_0/.DS_Store and b/product_crud_0/.DS_Store differ
diff --git a/product_crud_0/create.php b/product_crud_0/create.php
index cdb81b6..86c619b 100644
--- a/product_crud_0/create.php
+++ b/product_crud_0/create.php
@@ -1,7 +1,7 @@
setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+// establish connection
+require_once('database.php');
$title = '';
$description = '';
@@ -29,7 +29,7 @@
// if the image exists, save it somewhere
if($image && $image['tmp_name']){
// check if there is an image dir and make one if not
- if(!is_dir('images')){
+ if(!is_dir('images')){
mkdir('images');
}
@@ -64,44 +64,35 @@ function random_string($n){
}
?>
-
-
-
-
-
- Products CRUD
-
-
-
-
-
Create new Product
+
-
-
-
-
-
-
-
+
Create new Product
+
+
+
+
+
+
+
+
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/product_crud_0/database.php b/product_crud_0/database.php
new file mode 100644
index 0000000..b7cacea
--- /dev/null
+++ b/product_crud_0/database.php
@@ -0,0 +1,6 @@
+setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+// return $pdo;
+?>
\ No newline at end of file
diff --git a/product_crud_0/delete.php b/product_crud_0/delete.php
index eb963d3..5a49d59 100644
--- a/product_crud_0/delete.php
+++ b/product_crud_0/delete.php
@@ -1,8 +1,8 @@
setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+// establish connection
+require_once('database.php');
$statment = $pdo->prepare('DELETE FROM products WHERE id = :id');
$statment->bindValue(':id', $id);
diff --git a/product_crud_0/images/.DS_Store b/product_crud_0/images/.DS_Store
new file mode 100644
index 0000000..252a3fd
Binary files /dev/null and b/product_crud_0/images/.DS_Store differ
diff --git a/product_crud_0/images/0diXCvdk/1F7C02DF-B9F6-46FD-BD08-D671372E860B.jpeg b/product_crud_0/images/0diXCvdk/1F7C02DF-B9F6-46FD-BD08-D671372E860B.jpeg
deleted file mode 100644
index 11b98dc..0000000
Binary files a/product_crud_0/images/0diXCvdk/1F7C02DF-B9F6-46FD-BD08-D671372E860B.jpeg and /dev/null differ
diff --git a/product_crud_0/images/Fb8AuUrf/ferrari.jpeg b/product_crud_0/images/Fb8AuUrf/ferrari.jpeg
deleted file mode 100644
index 0852b9a..0000000
Binary files a/product_crud_0/images/Fb8AuUrf/ferrari.jpeg and /dev/null differ
diff --git a/product_crud_0/images/NKdP1vT7/Screenshot 2022-11-22 at 13.15.13.png b/product_crud_0/images/NKdP1vT7/Screenshot 2022-11-22 at 13.15.13.png
deleted file mode 100644
index 9cd9fe6..0000000
Binary files a/product_crud_0/images/NKdP1vT7/Screenshot 2022-11-22 at 13.15.13.png and /dev/null differ
diff --git a/product_crud_0/images/IwGqqj0y/Screenshot 2022-11-22 at 13.15.13.png b/product_crud_0/images/board-bag.pngIoRy00kn/board-bag.png
similarity index 100%
rename from product_crud_0/images/IwGqqj0y/Screenshot 2022-11-22 at 13.15.13.png
rename to product_crud_0/images/board-bag.pngIoRy00kn/board-bag.png
diff --git a/product_crud_0/images/7Y79ITns/Screenshot 2022-11-22 at 12.45.17.png b/product_crud_0/images/bones-wheels.pngqMIOszNW/bones-wheels.png
similarity index 100%
rename from product_crud_0/images/7Y79ITns/Screenshot 2022-11-22 at 12.45.17.png
rename to product_crud_0/images/bones-wheels.pngqMIOszNW/bones-wheels.png
diff --git a/product_crud_0/images/e1KUWEEV/Screenshot 2022-11-22 at 13.15.13.png b/product_crud_0/images/e1KUWEEV/Screenshot 2022-11-22 at 13.15.13.png
deleted file mode 100644
index 9cd9fe6..0000000
Binary files a/product_crud_0/images/e1KUWEEV/Screenshot 2022-11-22 at 13.15.13.png and /dev/null differ
diff --git a/product_crud_0/images/qLRqQfaj/Screenshot 2022-11-22 at 13.15.13.png b/product_crud_0/images/qLRqQfaj/Screenshot 2022-11-22 at 13.15.13.png
deleted file mode 100644
index 9cd9fe6..0000000
Binary files a/product_crud_0/images/qLRqQfaj/Screenshot 2022-11-22 at 13.15.13.png and /dev/null differ
diff --git a/product_crud_0/images/qxRWfSah/Screenshot 2022-07-14 at 13.22.04.png b/product_crud_0/images/qxRWfSah/Screenshot 2022-07-14 at 13.22.04.png
deleted file mode 100644
index 7d49102..0000000
Binary files a/product_crud_0/images/qxRWfSah/Screenshot 2022-07-14 at 13.22.04.png and /dev/null differ
diff --git a/product_crud_0/images/aitxm9fl/rocket_ship.webp b/product_crud_0/images/rocket_ship.webpXKCvQJcB/rocket_ship.webp
similarity index 100%
rename from product_crud_0/images/aitxm9fl/rocket_ship.webp
rename to product_crud_0/images/rocket_ship.webpXKCvQJcB/rocket_ship.webp
diff --git a/product_crud_0/images/oD7ymoCs/wheelbarrow.jpeg b/product_crud_0/images/wheelbarrow.jpeg0mCH6oCw/wheelbarrow.jpeg
similarity index 100%
rename from product_crud_0/images/oD7ymoCs/wheelbarrow.jpeg
rename to product_crud_0/images/wheelbarrow.jpeg0mCH6oCw/wheelbarrow.jpeg
diff --git a/product_crud_0/index.php b/product_crud_0/index.php
index 5c29e9a..45e13d8 100644
--- a/product_crud_0/index.php
+++ b/product_crud_0/index.php
@@ -1,7 +1,7 @@
setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+// establish connection
+require_once('database.php');
$search = trim($_GET['search'] ?? '');
@@ -16,69 +16,58 @@
$statement->execute();
$products = $statement->fetchAll(PDO::FETCH_ASSOC);
-
?>
-
-
-
-
-
- Products CRUD
-
-
-
-
-
-
-
+
diff --git a/product_crud_0/update.php b/product_crud_0/update.php
index c987e63..c42a82b 100644
--- a/product_crud_0/update.php
+++ b/product_crud_0/update.php
@@ -3,8 +3,7 @@
$id = $_GET['id'];
// establish connection
-$pdo = new PDO('mysql:host=localhost;dbname=products_crud', 'root', 'root');
-$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+require_once('database.php');
// prepare statement and get values as associative array
$statement = $pdo->prepare('SELECT * FROM products WHERE id = :id');
@@ -37,12 +36,22 @@
if(empty($errors)){
// check if a new image was provided
if(!empty($_FILES['image']['tmp_name'])){
+ // var_dump($values);
+ // exit;
+ var_dump($values['image']);
+ $image_directory = dirname($values['image']);
+ var_dump($image_directory);
+ // exit;
+ $diditwork = unlink($values['image']);
+ var_dump($diditwork);
+ rmdir($image_directory);
+ // exit;
$image = $_FILES['image'];
if(!is_dir('images')){
mkdir('images');
}
// make a unique path for the image, make directory, and move the image there
- $image_path = 'images/'. random_string(8). '/'. $image['name'];
+ $image_path = 'images/'. $image['name']. random_string(8). '/'. $image['name'];
mkdir(dirname($image_path));
move_uploaded_file($image['tmp_name'], $image_path);
// update the image in the database
@@ -75,44 +84,35 @@ function random_string($n){
}
?>
-
-
-
-
-
- Products CRUD
-
-
-
-
-
Edit
-
-
-
-
-
-
-
-
+
+
+
Edit
+
+
+
+
+
+
+
+
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/product_crud_0/views/partials/footer.php b/product_crud_0/views/partials/footer.php
new file mode 100644
index 0000000..691287b
--- /dev/null
+++ b/product_crud_0/views/partials/footer.php
@@ -0,0 +1,2 @@
+