add function to post an offer
This commit is contained in:
parent
b08ea12eda
commit
d59ee2fb11
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
include 'functions.php';
|
||||
date_default_timezone_set('Europe/Amsterdam');
|
||||
$demandId = $_POST['demandId'];
|
||||
?>
|
||||
<!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>Enter your offer</h2>
|
||||
<form class= 'post-box p' method='POST' action=''>
|
||||
<input type='hidden' name='demandId' value='<?php echo $demandId?>'>
|
||||
Quality<br>
|
||||
<select name='quality'>
|
||||
<option selected='selected' value='1'>New</option>
|
||||
<option value='2'>Used</option>
|
||||
</select><br>
|
||||
<br>
|
||||
Amount you can deliver<br>
|
||||
<input type='number' name='pieces' value='' required><br>
|
||||
<br>
|
||||
Name your price<br>
|
||||
<input type='number' name='price' 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>
|
||||
<?php
|
||||
post_offer();
|
||||
?>
|
||||
</body>
|
||||
</html>
|
|
@ -209,7 +209,11 @@ function show_demand ()
|
|||
echo "<br>
|
||||
<br>
|
||||
<strong>Description:</strong><br>";
|
||||
echo $demand_rows->demandText;
|
||||
echo "$demand_rows->demandText<br><br>";
|
||||
echo "<form method= 'POST' action='add_offer.php'>
|
||||
<input type='hidden' name='demandId' value='$demand_rows->demandId'>
|
||||
<button>Post Offer</button>
|
||||
</form>";
|
||||
}
|
||||
|
||||
function post_offer()
|
||||
|
@ -217,15 +221,53 @@ function post_offer()
|
|||
if (isset($_POST['submit'])) {
|
||||
global $con;
|
||||
$userId = get_userid();
|
||||
$demandId = $_POST['demandId'];
|
||||
$pieces = $_POST['pieces'];
|
||||
$price = $_POST['price'];
|
||||
$qualityId = $_POST['quality'];
|
||||
$text = $_POST['text'];
|
||||
// Inserts Data into Database
|
||||
$sql = "INSERT INTO offers (pieces, text, price, userId, qualityId)
|
||||
VALUES ('$pieces', '$text', '$price', '$userId', '$qualityId')";
|
||||
$sql = "INSERT INTO offers (pieces, text, price, userId, qualityId,
|
||||
demandId)
|
||||
VALUES ('$pieces', '$text', '$price', '$userId', '$qualityId',
|
||||
'$demandId')";
|
||||
$result = mysqli_query($con, $sql) or die(mysqli_error($con));
|
||||
}
|
||||
}
|
||||
|
||||
function show_offer ()
|
||||
{
|
||||
global $con;
|
||||
$demandId = $_POST['demandId'];
|
||||
|
||||
// get the offers matching the demand from the database
|
||||
$offer_query = "SELECT * FROM offers where demandId='$demandId'";
|
||||
$offer_query_result = mysqli_query($con, $offer_query) or
|
||||
die(mysqli_error($con));
|
||||
|
||||
// if the query on the database returned data print the data
|
||||
while ($offer_rows = $offer_query_result->fetch_object()) {
|
||||
$qualityId = $offer_rows->qualityId;
|
||||
$quality_query = "SELECT * FROM quality where qualityId='$qualityId'";
|
||||
$quality_query_result = mysqli_query($con, $quality_query) or
|
||||
die(mysqli_error($con));
|
||||
$quality_rows = $quality_query_result->fetch_object();
|
||||
|
||||
echo "<strong>Offer Nr: </strong>" . $offer_rows->offerId;
|
||||
echo "<br>
|
||||
<br>";
|
||||
echo "<strong>Amount available: </strong>" . $offer_rows->pieces;
|
||||
echo "<br>
|
||||
<br>";
|
||||
echo "<strong>Price per piece: </strong>" . $offer_rows->price;
|
||||
echo "<br>
|
||||
<br>";
|
||||
echo "<strong>Provided Quality: </strong>" . $quality_rows->qualityName;
|
||||
echo "<br>
|
||||
<br>
|
||||
<strong>Description:</strong><br>";
|
||||
echo $offer_rows->text . "<br>
|
||||
<hr>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -31,9 +31,8 @@ include 'functions.php';
|
|||
show_demand();
|
||||
?>
|
||||
</div>
|
||||
<br>
|
||||
<form method= 'POST' action='add_offer.php'>
|
||||
<button>Post Offer</button>
|
||||
</form>
|
||||
<?php
|
||||
show_offer();
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -60,14 +60,16 @@ CREATE TABLE if not exists `offers` (
|
|||
`text` text CHARACTER SET utf8 COLLATE utf8_bin,
|
||||
`price` float NOT NULL,
|
||||
`pieces` int(11) NOT NULL,
|
||||
`delivery` bool NOT NULL,
|
||||
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`userId` int(11) NOT NULL,
|
||||
`qualityId` int(11) NOT NULL,
|
||||
`demandId` int(11) NOT NULL,
|
||||
CONSTRAINT `fk_offers_userId`
|
||||
FOREIGN KEY (userId) REFERENCES users (userId),
|
||||
CONSTRAINT `fk_offers_qualityId`
|
||||
FOREIGN KEY (qualityId) REFERENCES quality (qualityId)
|
||||
CONSTRAINT `fk_offers_qualityId`
|
||||
FOREIGN KEY (qualityId) REFERENCES quality (qualityId),
|
||||
CONSTRAINT `fk_offers_demandId`
|
||||
FOREIGN KEY (demandId) REFERENCES demands (demandId)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue