I have list of products in database. I am loading products on page load and then displaying. I will ask user to enter the quantity for each product. Now after submitting the form, I want to retrieve all those quantities against each product. Below is my current code.
<?php
$productList;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
echo 'Product form submitted';
foreach ($productList as $product) {
// Code to retrieve quantity
}
} else {
include_once '../classes/OrderService.php';
$orderService = new OrderService();
$productList = $orderService->loadProducts();
}
?>
Below is html part.
<?php foreach ($productList as $product) { ?>
<b><a href="#" onclick="displayProductDetails('<?php echo $product->getProductName(); ?>');">
<?php echo $product->getProductName();?></a></b>
<br/>
<?php echo $product->getDescription();?>
<br/>
<b>Price:</b> <?php echo $product->getPrice(); ?>
<br/><br/>
Qantity: <input type="text" style="padding-left: 5px;" name="<?php echo $product->getQuantity(); ?>" size="3" maxlength="3"/>
<?php } ?>
I have two problems here. First is when I submit the form and control goes to submit if block my product list is empty. Why it is empty if I have already populated while loading the page. Also how to get the quantity of every product entered by user.
Thanks in advance.