Ik ben momenteel met school bezig en loop tegen het probleem
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\Eindopdracht 1.6\bestel.php on line 49
Ik heb dit online bekeken en vond een oplossing om te bekijken of het wel een array of object is, dit was het helaas niet.
Code:
<?php if ($conn->query( $sql ) ) {
$bestelnummer = $conn->insert_id;
$producten = $_POST['aantal'];
foreach ($producten as $productnummer => $aantal) {
if ($aantal > 0) {
$sql = "INSERT INTO 'bestelregel' ('bestelnummer', 'productnummer', 'aantal')
VALUES ('" . $bestelnummer . "', '" . $productnummer . "', '" . $aantal . "')";
$conn->query($sql);
echo "Bestelling is succesvol geplaatst met bestelnummer: " . $bestelnummer;
}
}
}
?>
En
<?php
$sql = 'SELECT * FROM producten WHERE categorie = "wijnen"';
$result = $conn->query($sql);
$categorie = ("Wijnen");
if ($result->num_rows > 0) {
echo '
<div class="form-group col-md-6">
<table class="table">
<thead>
<h2 class="ml-1">' . $categorie . '</h2>
<tr>
<th class="col-md-1">Product</th>
<th>Prijs</th>
<th>Aantal</th>
</tr>
</thead>
<tbody>
';
while($row = $result->fetch_assoc()) {
echo '
<tr>
<td>' . $row['naam'] . '</td>
<td>' . $row['prijs'] . '</td>
<td> <input type="text" class="form-control" class="w-100" name="aantal"> </input></td>
</tr>
'; }
echo '</tbody>
</table>
</div>';
} else {
echo '0 results';
}
?>
Horen hierbij, ik hoop dat iemand mij hier mee kan helpen.
3.113 views