123456/V5 PO PHP/Max en Pepijn/winkelwagen.php
<?php
include('functions.php');
include('db.php');
$best = '';
$verwijder = $_GET['vw_prod'];
if(isset($verwijder)){
$cookie = $_COOKIE['producten'];
$test1 = explode(",", $cookie);
$nieuwCookie = "";
foreach($test1 as $id){
// echo "<div>$id</div>";
if($id != $verwijder){
$nieuwCookie .= $id . ",";
// echo "<div>$id | $verwijder</div>";
}
}
setcookie("producten", $nieuwCookie, time() + 3600);
// echo "$verwijder<div>";
// echo $nieuwCookie;
header("Location: winkelwagen.php");
}
$cookie = $_COOKIE['producten'];
$productId = explode(",", $cookie);
if(isset($_POST['bestellen'])){
$cookie = $_COOKIE['producten'];
$test1 = explode(",", $cookie);
foreach($test1 as $id){
$temp = explode("_", $id);
$id = $temp[0];
$aantal = $temp[1];
$query = "UPDATE verkoopprijzen SET aanbod = aanbod - $aantal WHERE productid = $id";
mysqli_query($db, $query) or die(mysqli_error($db).$query);
setcookie("producten", $nieuwCookie, time() - 3600);
$best = 'Het is succesvol besteld';
}
}
if(isset($_POST['leveren'])){
$cookie = $_COOKIE['producten'];
$test1 = explode(",", $cookie);
foreach($test1 as $id){
$temp = explode("_", $id);
$id = $temp[0];
$aantal = $temp[1];
$query = "UPDATE verkoopprijzen SET aanbod = aanbod + $aantal WHERE productid = $id";
mysqli_query($db, $query) or die(mysqli_error($db).$query);
setcookie("producten", $nieuwCookie, time() - 3600);
$best = 'Het is succesvol geleverd';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="style.css">
<style>
table tr th{
border-bottom: 1px solid black;
padding-left: 5px;
padding-right: 5px;
}
table tr td{
padding-left: 5px;
padding-right: 5px;
}
table {
padding-left:10px;
padding-right:10px;
}
.zestig{
width: 60%;
}
.tien{
width: 10%;
}
.twintig{
width: 20%;
}
table {
width: 100%;
}
</style>
</head>
<body>
<?php
include "nav.php";
?>
<div class="content winkelwagen">
<?php echo "<h3>$best<h3>";?>
<h1>Winkelwagen</h1>
<!-- <div class="producten"> -->
<table>
<tr>
<th class="zestig">Product</th>
<th class="tien">Aantal</th>
<th class="twintig">Totale prijs</th>
<th class="tien" id="geen_border"></th>
</tr>
<?php
$totaal = 0;
if ($productId) {
foreach($productId as $product){
if (!empty($product)) {
$productInfo = explode("_", $product);
$id = $productInfo[0];
$count = $productInfo[1];
if (!empty($id) && !empty($count)) {
$query = "SELECT * FROM producten, verkoopprijzen WHERE producten.productid = $id AND verkoopprijzen.productid = $id";
$result = mysqli_query($db, $query) or die(mysqli_error($db).$query);
$product = mysqli_fetch_row($result);
$totaal += $product[7];
echo "<tr>";
echo "<td class='zestig'>$product[1]</td>";
echo "<td class='tien'>$count</td>";
echo "<td class='twintig'>€ ".($product[7]*$count)."</td>";
echo "<td class='tien'><a href='winkelwagen.php?vw_prod=$id".'_'."$count'>Verwijder</a></td>";
echo "</tr>";
}
}
}
echo "</table>";
echo '<form action="" method="POST">';
if(type_account()=='koper'){
echo "<input type='submit' name='bestellen' value='Bestellen'></div>";
}
else if (type_account()=='leverancier'){
echo "<input type='submit' name='leveren' value='Leveren'></div>";
}
else if(ingelogd_admin()){
echo "<input type='submit' name='leveren' value='Leveren'></div><input type='submit' name='bestellen' value='Bestellen'></div>";
}
else{
echo "<div style='text-align: center;'>U moet ingelogd zijn om producten te kunnen bestellen of leveren</div>";
}
} else {
echo "</table><br><br><br>
<div style='text-align: center;'>Er zitten geen producten in de winkelwagen</div>
<br><br>";
}
?>
</div>
</body>
</html>
Resultaat
Made by Thijs Aarnoudse