diff --git a/Aindex.php b/Aindex.php index 6c89e47..591cc74 100644 --- a/Aindex.php +++ b/Aindex.php @@ -1,32 +1,25 @@ + -

Fill the input fields to interact

+
+
-
-
-
-
-
-
-

-

-


- -
+
+
+

$product_name

+
+
+

$product_info

+
+
+ +
+

$product_owner_name

+
+
+
- - - \ No newline at end of file + \ No newline at end of file diff --git a/database.sql b/database.sql index 1c8212e..9e18d22 100644 --- a/database.sql +++ b/database.sql @@ -32,13 +32,21 @@ CREATE TABLE IF NOT EXISTS botiga_php_db.bp_users ( bp_product_img_02 VARCHAR(32), bp_product_img_03 VARCHAR(32), bp_product_addDate DATE NOT NULL, + bp_product_owner INT, PRIMARY KEY (bp_product_id), - FOREIGN KEY (bp_product_category) REFERENCES bp_categories(bp_category_id) + FOREIGN KEY (bp_product_category) REFERENCES bp_categories(bp_category_id), + FOREIGN KEY (bp_product_owner) REFERENCES bp_users(bp_user_id) ); INSERT INTO `bp_categories` (`bp_category_id`, `bp_category_name`) VALUES (NULL, 'Wooden'), (NULL, 'Brick'), (NULL, 'Stone'), (NULL, 'Alimium'), (NULL, 'Mix'); -INSERT INTO bp_products VALUES (NULL, 'Hanni Koroma', 'Japanese designed wooden nordic house', '95000', '1', 'house01.jpg', 'house02.jpg', 'house03.jpg', '2001-11-22'); -INSERT INTO bp_products VALUES (NULL, 'Fiskarhedenvillan', 'Classic 20th century English brick house', '200000', '2', 'house04.jpg', 'house05.jpg', 'house06.jpg', '1958-06-20'); -INSERT INTO bp_products VALUES (NULL, 'Barn House', 'American aluminium suspended house', '65000', '5', 'house07.jpg', 'house08.jpg', 'house09.jpg', '1994-09-11'); -INSERT INTO bp_products VALUES (NULL, 'Hygge', 'Nordic house built with a mix of natural materials', '150000', '5', 'house10.jpg', 'house11.jpg', 'house12.jpg', '2021-11-28'); +INSERT INTO bp_users VALUES (NULL, 'jones', '$2y$10$cQ/dbUCwpn70GxHyzLLG8O0KH0o67uagM8x0UASYXToTVplCFq4.m', '2021-12-09'); +INSERT INTO bp_users VALUES (NULL, 'jack', '$2y$10$nkeFH50KmNCQKxKrsE/NQu1gx5YMqPxrQyL9e/eRyY1p9j8GrOTe.', '2021-09-12'); +INSERT INTO bp_users VALUES (NULL, 'john', '$2y$10$c60U1n5hhploFWTGgnM3SOB5oSH70/f2sGvz1S5H3EZIeEul5x4ZK', '2021-10-11'); +INSERT INTO bp_users VALUES (NULL, 'jerry', '$2y$10$gtQrwpRjdydYJTTXLa5jWOK3/CYriXNDuUuHtFqrlQ1o2w7a7893u', '2021-11-10'); + + +INSERT INTO bp_products VALUES (NULL, 'Hanni Koroma', 'Japanese designed wooden nordic house', '95000', '1', 'house01.jpg', 'house02.jpg', 'house03.jpg', '2001-11-22', 1); +INSERT INTO bp_products VALUES (NULL, 'Fiskarhedenvillan', 'Classic 20th century English brick house', '200000', '2', 'house04.jpg', 'house05.jpg', 'house06.jpg', '1958-06-20', 2); +INSERT INTO bp_products VALUES (NULL, 'Barn House', 'American aluminium suspended house', '65000', '5', 'house07.jpg', 'house08.jpg', 'house09.jpg', '1994-09-11', 3); +INSERT INTO bp_products VALUES (NULL, 'Hygge', 'Nordic house built with a mix of natural materials', '150000', '5', 'house10.jpg', 'house11.jpg', 'house12.jpg', '2021-11-28', 4); diff --git a/form.php b/form.php index 6a757d0..a6ed7c0 100644 --- a/form.php +++ b/form.php @@ -1,7 +1,7 @@
- +

+
+

+ + + +
+
+ \ No newline at end of file diff --git a/login.php b/login.php new file mode 100644 index 0000000..9af646c --- /dev/null +++ b/login.php @@ -0,0 +1,39 @@ +prepare("SELECT bp_user_pass FROM bp_users WHERE bp_user_name = ?"); + $sql->bind_param("s", $username); + $sql->execute(); + $sql->bind_result($encryptedUserpass); + $sql->fetch(); + + return password_verify($userpass, $encryptedUserpass); + } + function userDetails($username, $con) { + $sql = $con->prepare("SELECT bp_user_id, bp_user_name FROM bp_users WHERE bp_user_name = ?"); + $sql->bind_param("s", $username); + $sql->execute(); + $sql->bind_result($bp_user_id, $bp_user_name); + $sql->fetch(); + + return (array("bp_user_id"=>$bp_user_id, "bp_user_name"=>$bp_user_name)); + + } + + ?> \ No newline at end of file diff --git a/my-products.php b/my-products.php new file mode 100644 index 0000000..1f7bb14 --- /dev/null +++ b/my-products.php @@ -0,0 +1,98 @@ + + +
+ +
+ Botiga_php +
+

Botiga php

+
+
+ +
+

Products

+
+ + + +
+
+ +
+ + = ? AND bp_product_price <= ?);"; + + $sql = $con->prepare($sqlString); + $sql->bind_param("ssidd", $productName, $productInfo, $productCategory, $minProductPrice, $maxProductPrice); + + } else { + $sqlString = "SELECT bp_product_id, bp_product_name, bp_product_price, bp_product_img_01 FROM bp_products WHERE bp_product_owner = ?"; + $sql = $con->prepare($sqlString); + $sql->bind_param("i", $userid); + + } + $sql->execute(); + + $sql->bind_result($bp_product_id, $bp_product_name, $bp_product_price, $bp_product_img_01); + while ($sql->fetch()) { + + echo (" + + "); + + } + ?> +
+
+ \ No newline at end of file diff --git a/parameters.php b/parameters.php index af2976f..85da979 100644 --- a/parameters.php +++ b/parameters.php @@ -1,4 +1,4 @@ \ No newline at end of file diff --git a/productDetail.php b/productDetail.php index bfd4b7c..718a724 100644 --- a/productDetail.php +++ b/productDetail.php @@ -5,14 +5,15 @@ include_once('parameters.php'); if (!(isset($_GET['bp_product_id']))) { header("Location: home.php"); } else { - $bp_product_id = $_GET['bp_product_id']; + $product_id = $_GET['bp_product_id']; } - -$sqlP = $con->prepare("SELECT * from bp_products where bp_product_id = ?"); -$sqlP->bind_param("i", $bp_product_id); +$sqlPString = "SELECT bp_product_name, bp_product_info, bp_product_price, bp_product_category, bp_product_img_01, bp_product_img_02, bp_product_img_03, bp_product_addDate, bp_user_name"; +$sqlPString .= " FROM bp_products INNER JOIN bp_users WHERE bp_product_owner = bp_user_id AND bp_product_id = ?"; +$sqlP = $con->prepare($sqlPString); +$sqlP->bind_param("i", $product_id); $sqlP->execute(); -$sqlP->bind_result($bp_product_id, $bp_product_name, $bp_product_info, $bp_product_price, $bp_product_category, $bp_product_img_01, $bp_product_img_02, $bp_product_img_03, $bp_product_addDate); +$sqlP->bind_result($product_name, $product_info, $broduct_price, $product_category, $product_img_01, $product_img_02, $product_img_03, $product_addDate, $product_owner_name); $sqlP->fetch(); @@ -28,9 +29,9 @@ $sqlP->fetch(); echo ("
- - - + + +
@@ -44,9 +45,22 @@ $sqlP->fetch();
-
-

$bp_product_name

-

$bp_product_info

+
+
+ +
+
+

$product_name

+
+
+

$product_info

+
+
+ +
+

Publisher:     $product_owner_name

+
+
"); diff --git a/register-page.php b/register-page.php new file mode 100644 index 0000000..ac64ed7 --- /dev/null +++ b/register-page.php @@ -0,0 +1,57 @@ + + +
+ +
+ Botiga_php +
+

Botiga php

+
+
+ +
+

Register

+
+ + +
+
+ +
+ +
+
+
+
+

+ +
+ + +
+
+ \ No newline at end of file diff --git a/register.php b/register.php new file mode 100644 index 0000000..0c24418 --- /dev/null +++ b/register.php @@ -0,0 +1,32 @@ +prepare("INSERT INTO bp_users(bp_user_name, bp_user_pass, bp_user_addDate) VALUES(?, ?, ?);"); + $sql->bind_param('sss', $username, $userpass, date("Y-m-d")); + $rs = $sql->execute(); + + if($rs) { + $response['success'] = true; + } else { + $response['success'] = false; + throw new Exception("Hi ha hagut un error al insertar el registre"); + } + + + // if($rs) { + // echo ("El registre ha estat satisfactori"); + // } else { + // echo ("Hi ha hagut un error al insertar el registre"); + // } + } catch( Exception $e ) { + $response['message'] = $e->getMessage(); + } + + echo json_encode($response); + + ?> \ No newline at end of file