I'm making an application for a restaurant(With php and pdo). I need to insert orders. I loop through some products that you can order with an input field so you can select how many of those products you want to order. But i don't know how to insert this in multiple records. so for example. i want to order 1 cola and 1 pepsi. it needs to create 2 records.
I tried to post the data but nothing happened
if (isset($_POST["addbestelling"])){
global $db;
$gerechtid = htmlspecialchars($_POST["GID"]);
$aantal = htmlspecialchars($_POST["aantalG"]);
$sql = "INSERT INTO bestelling(GerechtID, Aantal) VALUES (:gerechtid,:aantal)";
$stmt = $db->prepare($sql);
$data = array("gerechtid" => $gerechtid, "aantal" =>$aantal);
try {
$stmt->execute($data);
echo "<script>alert('Succesvol geplaatst!');</script>";
}
catch (PDOException $e) {
echo $e->getMessage();
}
}
$voorgerecht = "
SELECT g.*
, s.Subgerecht
FROM gerecht g
LEFT
JOIN subgerecht s
ON s.GerechtID = g.GerechtID
WHERE s.Subgerecht = 'Voorgerecht';
";
foreach($db->query($voorgerecht) as $vg){
<div class="name-price row">
<p class="pr10">Gerecht</p>
<p class="pr10">€Prijs</p>
<?php
<input type="number" class="form-control" name="aantalG" placeholder="Aantal">
<input type="hidden" name="GID" value="<?php echo $vg["GerechtID"];?>">
}
?>
<input type="submit" name="addbestelling" class="btn btn-dark" value="Voeg toe">
So i fill in the number of products i want to order but nothing happens when i submit it