<?php
session_start();
include("#nav.php");
include("dbconnectie.php");
echo "Plaatsingen: ";
$query = $db->prepare("SELECT * FROM shop");
$query->execute();
$result = $query->fetchALL(PDO::FETCH_ASSOC);
echo "<table>";
foreach($result as &$data) {
echo "<tr>";
$img = $data['img_url'];
echo "<td>" . $data["brand"] . "</td>";
echo "<td>" . $data["model"] . "</td>";
echo "<td> Condition: " . $data["cond"] . "/100 </td>";
echo "<td> Prijs: $ " . number_format($data["price"],2,",",".") . "</td>";
echo "<td> <img src='$img' width='400' height='300' ></img> </td>";
echo "<td> Plaatsing nummer: " . $data['id_img'] . "</td>";
echo "</tr>";
echo "<br>";
}
echo "</table>";
if(isset($_POST['atc']))
{
if($_SESSION['on']){
$myarray = array('0');
$addtoarray = $_GET['id'];
array_push($myarray, $addtoarray);
$_SESSION['cart'] = $myarray;
echo "Toegevoogd aan uw winkelmandje.";
var_dump($_SESSION['cart']);
}else
{
echo "Log eerst in!";
}
}
?>
<html>
<title>Just for kicks</title>
<header>
</header>
<body>
<form method='post' action=''>
Plaatsing nummer invoeren:
<input type='number' name ='id' value ='id'><br>
<button type="submit" class="submit" name="atc" value="atc">Winkelmadje</button><br><br>
</form>
</body>
</html>
Between line 25 and 31 I'm trying to add numbers to the session array but I'm not sure how, because this is clearly not working. It doesn't add the number you fill in, at the form part. But it appears it doesn't do anything.
POSTbut you're attempting to retrieve using theGET. You are settingvaluetoidin the form. Removevalue ='id'.$_SESSION['on']is never set so it will never go in there.