From 4871de62d3477a023b80e5d66b662a28922a0eb2 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 20 Feb 2017 20:56:02 +0100 Subject: [PATCH] Create a seperate page for adding demands In addition I've added a new field for quality. --- add_request.php | 62 +++++++++++++++++++++++++++++++++++++++++++++++ board.php | 16 +----------- functions.php | 17 +++++++------ navigation.php | 1 + sql/add_data.sql | 4 +++ sql/create_db.sql | 11 ++++++++- 6 files changed, 88 insertions(+), 23 deletions(-) create mode 100644 add_request.php diff --git a/add_request.php b/add_request.php new file mode 100644 index 0000000..113fa6f --- /dev/null +++ b/add_request.php @@ -0,0 +1,62 @@ + + + + + + + + + + + + + +
+
+
+ +

Board

+ + + + + +
+
+ + +
+

New entry

+ + + Title
+
+ Quality
+
+
+ Maximum
+
+
+ Minimum
+
+
+ Description
+
+ + + "; + ?> +
+ + diff --git a/board.php b/board.php index a58a0d7..e9e166c 100644 --- a/board.php +++ b/board.php @@ -32,24 +32,10 @@ date_default_timezone_set('Europe/Amsterdam');
- -

Neuer Eintrag

- +

Open Requests


Maximum
- -
Minimum
-
- -
Produktbeschreibung
-
- - "; pbget($con); ?> -
diff --git a/functions.php b/functions.php index a83db06..103f8f5 100644 --- a/functions.php +++ b/functions.php @@ -76,16 +76,19 @@ function pbinsert ($con) $userId = get_userid($con); $piecesMax = $_POST['piecesMax']; $piecesMin = $_POST['piecesMin']; - $date = $_POST['date']; + $qualityId = $_POST['quality']; + $title = $_POST['title']; $text = $_POST['text']; // Inserts Data into Database - $sql = "INSERT INTO demands ( piecesMax, piecesMin, text, date, userId) - VALUES ('$piecesMax', '$piecesMin', '$text', '$date', '$userId')"; + $sql = "INSERT INTO demands (piecesMax, piecesMin, demandText, + demandTitle, userId, qualityId) + VALUES ('$piecesMax', '$piecesMin', '$text', '$title', + '$userId', '$qualityId')"; $result = mysqli_query($con, $sql) or die(mysqli_error($con)); } } -// A function to insert the own posts from the database into the webside +// A function to insert the own posts from the database into the website function pbget($con) { global $con; @@ -94,7 +97,7 @@ function pbget($con) while ($row = $result->fetch_assoc()) { echo "

"; echo $row['date'] . "
"; - echo $row['text'] ."
" , "
Maximum
"; + echo $row['demandText'] ."
" , "
Maximum
"; echo $row['piecesMax'] ."
Minimum
"; echo $row['piecesMin']; echo "

@@ -109,7 +112,7 @@ function pbget($con) - +
"; @@ -131,7 +134,7 @@ function editpost($con) $sql = "UPDATE demands SET piecesMax='$piecesMax', piecesMin='$piecesMin', - text='$text' + demandText='$text' WHERE demandId='$demandId'"; $result = mysqli_query($con, $sql) or die(mysqli_error($con)); header("Location: board.php"); diff --git a/navigation.php b/navigation.php index 5d09565..b2313c7 100644 --- a/navigation.php +++ b/navigation.php @@ -2,6 +2,7 @@ echo '' ?> diff --git a/sql/add_data.sql b/sql/add_data.sql index 538c241..397a7ee 100644 --- a/sql/add_data.sql +++ b/sql/add_data.sql @@ -10,3 +10,7 @@ insert into users (userLogin, userPass, userEmail) values ('demander','password','demander@example.com'), ('provider','password','provider@example.com'), ('admin','password','admin@example.com'); + +insert into quality (qualityName) + values ('new'), + ('used'); diff --git a/sql/create_db.sql b/sql/create_db.sql index 7c25d06..019c145 100644 --- a/sql/create_db.sql +++ b/sql/create_db.sql @@ -31,16 +31,25 @@ CREATE TABLE if not exists `tags` ( `text` varchar(50) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE if not exists `quality` ( + `qualityId` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `qualityName` varchar(20) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + CREATE TABLE if not exists `demands` ( `demandId` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, - `text` text, + `demandTitle` varchar(50) NOT NULL, + `demandText` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `piecesMin` int(11) NOT NULL, `piecesMax` int(11) DEFAULT NULL, `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `qualityId` int(11) NOT NULL, `userId` int(11) NOT NULL, `tagId` int(11) NULL, CONSTRAINT `fk_demands_userId` FOREIGN KEY (userId) REFERENCES users (userId), + CONSTRAINT `fk_demands_qualityId` + FOREIGN KEY (qualityId) REFERENCES quality (qualityId), CONSTRAINT `fk_tagId` FOREIGN KEY (tagId) REFERENCES tags (tagId) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;