Create a seperate page for adding demands

In addition I've added a new field for quality.
This commit is contained in:
Andreas Zweili 2017-02-20 20:56:02 +01:00
parent a1bde1f459
commit 4871de62d3
6 changed files with 88 additions and 23 deletions

62
add_request.php Normal file
View File

@ -0,0 +1,62 @@
<?php
include 'functions.php';
date_default_timezone_set('Europe/Amsterdam');
?>
<!DOCTYPE html>
<html>
<head>
<!-- enable utf-8 encoding for umlauts etc.-->
<meta charset="utf-8">
<!-- Description of what this dose -->
<meta name ="viewport" content="width=device-width, initial-scale=1">
<!-- link to the default css file -->
<link rel="stylesheet" href="css/stylesheet.css"/>
</head>
<body>
<div>
<div>
<header>
<!-- The title begins here -->
<h1>Board</h1>
<!--The Title ends here -->
<!-- The sidebar naviagtion begins here -->
<nav>
<?php
include 'navigation.php';
?>
</nav>
<!-- The sidebar naviagtion ends here -->
</header>
</div>
<!-- The Post function begins here -->
<div>
<h2>New entry</h2>
<?php
echo "<form class= 'post-box p' method='POST' action='".pbinsert($con)."'>
Title<br>
<input type='text' name='title' required><br>
Quality<br>
<select name='quality'>
<option selected='selected' value='1'>New</option>
<option value='2'>Used</option>
</select><br>
<br>
Maximum<br>
<input type='number' name='piecesMax' value='' ><br>
<br>
Minimum<br>
<input type='number' name='piecesMin' value='' required><br>
<br>
Description<br>
<textarea rows='6' cols='40' name='text' required></textarea><br>
<button type='submit' name='submit'>SUBMIT</button>
</form>
";
?>
</div>
</body>
</html>

View File

@ -32,24 +32,10 @@ date_default_timezone_set('Europe/Amsterdam');
</div>
<!-- The Post function begins here -->
<div>
<h2>Neuer Eintrag</h2>
<h2>Open Requests</h2>
<?php
echo
"<form class= 'post-box p' method='POST' action='".pbinsert($con)."'> <br /> Maximum<br/>
<input type='hidden' name='userId' value=''>
<input type='number' name='piecesMax' value='' > <br /> Minimum<br/>
<input type='number' name='piecesMin' value='' > <br />
<input type='hidden' name='date' value='".date('Y-m-d H:i:s')."'>
<br /> Produktbeschreibung<br/>
<textarea rows='6' cols='40' name='text'></textarea><br />
<button type='submit' name='submit'>SUBMIT</button>
</form>";
pbget($con);
?>
</div>
</body>
</html>

View File

@ -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 "<div class='post-box'><p>";
echo $row['date'] . "<br>";
echo $row['text'] ."<br>" , "<br /> Maximum<br/>";
echo $row['demandText'] ."<br>" , "<br /> Maximum<br/>";
echo $row['piecesMax'] ."<br /> Minimum<br/>";
echo $row['piecesMin'];
echo "</p>
@ -109,7 +112,7 @@ function pbget($con)
<input type='hidden' name='piecesMax' value='".$row['piecesMax']."'>
<input type='hidden' name='piecesMin' value='".$row['piecesMin']."'>
<input type='hidden' name='date' value='".$row['date']."'>
<input type='hidden' name='text' value='".$row['text']."'>
<input type='hidden' name='text' value='".$row['demandText']."'>
<button>Edit</button>
</form>
</div>";
@ -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");

View File

@ -2,6 +2,7 @@
echo '<ul>
<li><a href="index.php">Logout</a></li>
<li><a href="board.php">Board</a></li>
<li><a href="add_request.php">New Request</a></li>
<li><a class="active" href="home.php">Home</a></li>
</ul>'
?>

View File

@ -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');

View File

@ -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;