check if the maximumPieces is bigger than the minimumPieces

This commit is contained in:
Andreas Zweili 2017-02-20 22:05:30 +01:00
parent 27ee918b63
commit b4f3db4208
4 changed files with 29 additions and 72 deletions

View File

@ -46,7 +46,7 @@ date_default_timezone_set('Europe/Amsterdam');
</select><br>
<br>
Maximum<br>
<input type='number' name='piecesMax' value='' ><br>
<input type='number' name='piecesMax' value='' required><br>
<br>
Minimum<br>
<input type='number' name='piecesMin' value='' required><br>

View File

@ -94,3 +94,6 @@ li {
.delete-form button:hover{
opacity: 1;
}
*.warning {
color:red;
}

View File

@ -80,11 +80,17 @@ function post_demand ($con)
$title = $_POST['title'];
$text = $_POST['text'];
// Inserts Data into Database
$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));
if ($piecesMax <= $piecesMin) {
echo "<strong class='warning'>
The Maximum must be bigger than the Minimum!
</strong>";
} else {
$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));
}
}
}
@ -131,14 +137,20 @@ function edit_demand ($con)
$text = $_POST['text'];
// Inserts Updates Database
$sql = "UPDATE demands
SET piecesMax='$piecesMax',
piecesMin='$piecesMin',
demandTitle='$title',
demandText='$text'
WHERE demandId='$demandId'";
$result = mysqli_query($con, $sql) or die(mysqli_error($con));
header("Location: board.php");
if ($piecesMax <= $piecesMin) {
echo "<strong class='warning'>
The Maximum must be bigger than the Minimum!
</strong>";
} else {
$sql = "UPDATE demands
SET piecesMax='$piecesMax',
piecesMin='$piecesMin',
demandTitle='$title',
demandText='$text'
WHERE demandId='$demandId'";
$result = mysqli_query($con, $sql) or die(mysqli_error($con));
header("Location: board.php");
}
}
}
// A function to delete a post

View File

@ -1,58 +0,0 @@
<?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>Edit</h1>
<!-- The title ends here -->
<!-- The sidebar naviagtion begins here -->
<nav>
<?php
include 'navigation.php';
?>
</nav>
<!-- The sidebar naviagtion ends here -->
</header>
</div>
<!-- Edit function begins here -->
<h2>Edit Board</h2>
<?php
$userId = $_POST['userId'];
$demandId = $_POST['demandId'];
$piecesMax = $_POST['piecesMax'];
$piecesMin = $_POST['piecesMin'];
$title= $_POST['title'];
$text = $_POST['text'];
echo
"<form method='POST' action='".edit_post($con)."'>
<input type='text' name='title' value='".$title."'><br>
<input type='hidden' name='userId' value='".$userId."'>
<input type='hidden' name='demandId' value='".$demandId."'><br /> Maximum<br/>
<input type='number' name='piecesMax' value='".$piecesMax."'> <br /> Minimum<br/>
<input type='number' name='piecesMin' value='".$piecesMin."'>
<br /> Produktbeschreibung<br/>
<textarea name='text'>".$text."</textarea><br />
<button type='submit' name='edit'>Edit</button>
</form>";
?>
</div>
</body>
</html>