Compare commits

..

4 Commits

Author SHA1 Message Date
17e5f0d5dc Change size column to float type 2022-07-29 12:35:29 +02:00
7742235180 Change price input type 2022-07-29 12:23:30 +02:00
b9bf831001 Fix DDL.sql 2022-07-29 12:15:14 +02:00
b09e8fff28 Remove hard coded credentials 2022-07-29 11:54:09 +02:00
4 changed files with 11 additions and 15 deletions

View File

@@ -1,3 +1,5 @@
DROP DATABASE IF EXISTS `products`;
CREATE DATABASE `products`; CREATE DATABASE `products`;
USE `products`; USE `products`;
@@ -9,7 +11,7 @@ CREATE TABLE `product` (
`sku` varchar(100) NOT NULL, `sku` varchar(100) NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `sku` (`sku`) UNIQUE KEY `sku` (`sku`)
) );
CREATE TABLE `book` ( CREATE TABLE `book` (
`id` int unsigned NOT NULL AUTO_INCREMENT, `id` int unsigned NOT NULL AUTO_INCREMENT,
@@ -18,16 +20,16 @@ CREATE TABLE `book` (
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `book_UN` (`product_id`), UNIQUE KEY `book_UN` (`product_id`),
CONSTRAINT `book_FK` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`) CONSTRAINT `book_FK` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`)
) );
CREATE TABLE `dvd` ( CREATE TABLE `dvd` (
`id` int unsigned NOT NULL AUTO_INCREMENT, `id` int unsigned NOT NULL AUTO_INCREMENT,
`product_id` int unsigned NOT NULL, `product_id` int unsigned NOT NULL,
`size` int unsigned NOT NULL, `size` float NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `dvd_UN` (`product_id`), UNIQUE KEY `dvd_UN` (`product_id`),
CONSTRAINT `dvd_FK` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`) CONSTRAINT `dvd_FK` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`)
) );
CREATE TABLE `furniture` ( CREATE TABLE `furniture` (
`id` int unsigned NOT NULL AUTO_INCREMENT, `id` int unsigned NOT NULL AUTO_INCREMENT,
@@ -38,5 +40,4 @@ CREATE TABLE `furniture` (
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `furniture_UN` (`product_id`), UNIQUE KEY `furniture_UN` (`product_id`),
CONSTRAINT `furniture_FK` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`) CONSTRAINT `furniture_FK` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`)
) );

View File

@@ -74,7 +74,7 @@ class DVD extends Product
$size = $this->getSize(); $size = $this->getSize();
$stmt = $conn->prepare("INSERT INTO ".DVD." (product_id, size) VALUES (?, ?);"); $stmt = $conn->prepare("INSERT INTO ".DVD." (product_id, size) VALUES (?, ?);");
$stmt->bind_param('ii', $productId, $size); $stmt->bind_param('id', $productId, $size);
if ($stmt->execute() === true) { if ($stmt->execute() === true) {
$this->setVariationId($conn->insert_id); $this->setVariationId($conn->insert_id);

View File

@@ -8,15 +8,10 @@ define("FURNITURE", "furniture");
class Database class Database
{ {
const SERVERNAME = "127.0.0.1";
const DATABASE = "scandiweb";
const USERNAME = "root";
const PASSWORD = "root";
public static function connect() public static function connect()
{ {
$conn = new \mysqli(self::SERVERNAME, self::USERNAME, self::PASSWORD); $conn = new \mysqli(getenv('SERVERNAME'), getenv('USERNAME'), getenv('PASSWORD'));
$conn->select_db(self::DATABASE); $conn->select_db(getenv('DATABASE'));
return $conn; return $conn;
} }
} }

View File

@@ -26,7 +26,7 @@
</tr> </tr>
<tr> <tr>
<td><label for="price">Price ($)</label></td> <td><label for="price">Price ($)</label></td>
<td><input type="number" id="price" name="price" required></td> <td><input type="text" id="price" name="price" required></td>
</tr> </tr>
</table> </table>
</div> </div>