From 7f8589fed6fe84588d4c4266e56032e1d1c0f8b4 Mon Sep 17 00:00:00 2001 From: "johnny@pittpc.com" Date: Sat, 28 Sep 2019 14:16:16 -0400 Subject: [PATCH] Added category to products, also new db dump to include category_id under products Thanks @kristankenney --- add_product_modal.php | 25 +++++++++++++++++++++++++ db.sql | 3 ++- edit_product_modal.php | 24 ++++++++++++++++++++++++ post.php | 6 ++++-- products.php | 6 +++++- 5 files changed, 60 insertions(+), 4 deletions(-) diff --git a/add_product_modal.php b/add_product_modal.php index 2d22c9c6..2d10f10a 100644 --- a/add_product_modal.php +++ b/add_product_modal.php @@ -13,6 +13,31 @@ + +
+ +
+
+ +
+ +
+
+
diff --git a/db.sql b/db.sql index 3508b177..c4dd27af 100644 --- a/db.sql +++ b/db.sql @@ -502,6 +502,7 @@ CREATE TABLE `products` ( `product_cost` decimal(15,2) NOT NULL, `product_created_at` datetime NOT NULL, `product_updated_at` datetime DEFAULT NULL, + `category_id` int(11) NOT NULL, `company_id` int(11) NOT NULL, PRIMARY KEY (`product_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; @@ -818,4 +819,4 @@ CREATE TABLE `vendors` ( /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2019-09-23 22:21:26 +-- Dump completed on 2019-09-28 14:15:08 diff --git a/edit_product_modal.php b/edit_product_modal.php index a4d86407..e2165454 100644 --- a/edit_product_modal.php +++ b/edit_product_modal.php @@ -14,6 +14,30 @@
+ +
+ +
+
+ +
+ +
+
+
diff --git a/post.php b/post.php index 96de6027..a8ce5a9d 100644 --- a/post.php +++ b/post.php @@ -847,8 +847,9 @@ if(isset($_POST['add_product'])){ $name = strip_tags(mysqli_real_escape_string($mysqli,$_POST['name'])); $description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description'])); $cost = floatval($_POST['cost']); + $category = intval($_POST['category']); - mysqli_query($mysqli,"INSERT INTO products SET product_name = '$name', product_description = '$description', product_cost = '$cost', product_created_at = NOW(), company_id = $session_company_id"); + mysqli_query($mysqli,"INSERT INTO products SET product_name = '$name', product_description = '$description', product_cost = '$cost', product_created_at = NOW(), category_id = $category, company_id = $session_company_id"); //Logging mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Product', log_action = 'Created', log_description = '$name', log_created_at = NOW(), company_id = $session_company_id, user_id = $session_user_id"); @@ -865,8 +866,9 @@ if(isset($_POST['edit_product'])){ $name = strip_tags(mysqli_real_escape_string($mysqli,$_POST['name'])); $description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description'])); $cost = floatval($_POST['cost']); + $category = intval($_POST['category']); - mysqli_query($mysqli,"UPDATE products SET product_name = '$name', product_description = '$description', product_cost = '$cost', product_updated_at = NOW() WHERE product_id = $product_id AND company_id = $session_company_id"); + mysqli_query($mysqli,"UPDATE products SET product_name = '$name', product_description = '$description', product_cost = '$cost', product_updated_at = NOW(), category_id = $category WHERE product_id = $product_id AND company_id = $session_company_id"); //Logging mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Product', log_action = 'Modified', log_description = '$name', log_created_at = NOW(), company_id = $session_company_id, user_id = $session_user_id"); diff --git a/products.php b/products.php index 868aca48..5451af61 100644 --- a/products.php +++ b/products.php @@ -39,7 +39,7 @@ $disp = "ASC"; } - $sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM products WHERE product_name LIKE '%$q%' AND company_id = $session_company_id ORDER BY $sb $o LIMIT $record_from, $record_to"); + $sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM products, categories WHERE products.category_id = categories.category_id AND products.company_id = $session_company_id AND (product_name LIKE '%$q%' OR category_name LIKE '%$q%') ORDER BY $sb $o LIMIT $record_from, $record_to"); $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()")); $total_found_rows = $num_rows[0]; @@ -68,6 +68,7 @@ "> Name + Category Description Cost Action @@ -81,10 +82,13 @@ $product_name = $row['product_name']; $product_description = $row['product_description']; $product_cost = $row['product_cost']; + $category_id = $row['category_id']; + $category_name = $row['category_name']; ?> + $