Hi everyone,
I am trying to create a basic quote system that pulls products from my Database and allows a user to select multiple products via a Checkbox and then receive a instant PDF quote once they have selected the products and submitted the form.
So far, the form works brilliantly. However, other employees of the business I work for requested that I add a Quantity box next to each product so they can input the number they require which will then update the price to however many they request. For example, Product A is £20, if they type 4 in the Quantity box, then Product A becomes £80… Here is my form so far.
[code=php]
<?php
$servername = ‘REMOVED’;
$username = ‘REMOVED’;
$password = ‘REMOVED’;
$dbname = ‘REMOVED’;
try {
$conn = new PDO(“mysql:host=$servername;dbname=$dbname”, $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare(“SELECT id_product, price, unity FROM ps_product”);
$stmt->execute();
$product = $stmt->fetchAll();
echo ‘<div class=”table-responsive”>’;
echo ‘<table class=”table table-striped”>’;
echo ‘<th>Checkbox</th><th>Product Reference</th><th>Product Name</th><th>Price</th><th>Unit</th><th>Quantity</th>’;
foreach ($product as $rowProd) {
$stmt = $conn->prepare(“SELECT reference, price FROM ps_product_attribute WHERE id_product = “. $rowProd[“id_product”] .””);
$stmt->execute();
$attribute = $stmt->fetchAll();
$stmt = $conn->prepare(“SELECT name FROM ps_product_lang WHERE id_product = “. $rowProd[“id_product”] .””);
$stmt->execute();
$name = $stmt->fetchAll();
foreach ($name as $rowName) {
$productName = $rowName[‘name’];
}
foreach ($attribute as $rowAttr) {
if($rowAttr[“price”] == 0 OR $rowAttr[“price”] < $rowProd[“price”]) {
$rowAttr[“price”] = $rowAttr[“price”] + $rowProd[“price”];
}
if($rowProd[“unity”] == false) {
$rowProd[“unity”] = 1;
}
$reference = ‘Reference’;
$price = ‘Price’;
$unit = ‘Unit’;
print ‘<tr>’;
print ‘<td><input type=”checkbox” name=”product[]” value=”‘. $rowAttr[“reference”] .’;’. $productName .’;’. number_format($rowAttr[“price”], 2) .’;’. $rowProd[“unity”] .'”></td>’;
print ‘<td>’. $rowAttr[“reference”] .'</td>’;
print ‘<td>’. $productName .'</td>’;
print ‘<td>£’. number_format($rowAttr[“price”], 2) .'</td>’;
print ‘<td>’. $rowProd[“unity”] .'</td>’;
print ‘<td><input type=”number” name=”quantity” min=”1″ style=”padding: 0px 5px; max-width: 75px;” required /></td>’;
print ‘</tr>’;
}
}
echo ‘</table>’;
echo ‘</div>’;
}
catch(PDOException $e) {
echo “Error: ” . $e->getMessage();
}
$conn = null;
?>
I got as far as adding: <td><input type=”number” name=”quantity” min=”1″ style=”padding: 0px 5px; max-width: 75px;” required /></td> and then was left confused at what I would do next.
Any help would be greatly appreciated.
Thanks.