I am trying to create a small shopping cart and I am getting this error
Notice: Undefined index: quantity in C:\wamp\www\bakery\BakeryNewOrderConfirm.php on line 31
I am using the following php files and an sql file
bakerynew.php
BakeryRVCC Bakery
ProductId | Product Name | Unit Price | Quantity |
---|
".($i+1)." | "; echo "".$row['ProductName']." | "; echo "".$row['UnitPrice']." | "; $quant = "quantity".$i; echo "" .$quant. " | "; echo ""; echo " |
bakeryneworderdetails.php
Bakery Order DetailsBakery Order Details
RVCC Bakery
ProductName | Unit Price | Quantity | Total Price |
---|
@ $db = new mysqli('localhost', 'root', '', 'bakery');
if (mysqli_connect_errno()) {
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
$query = "select * from product";
$result = $db->query($query);
$num_results = $result->num_rows;
$totalPrice = 0;
// Note that $snacks will be an array.
for ($i=0; $i <$num_results; $i++) {
$row = $result->fetch_assoc();
echo “
”.$row[‘ProductName’]." | ";”.$row[‘UnitPrice’]." | ";”.$quant." | ";”.$price." | ";
";
}
echo "Total Price for this order: ".$totalPrice;
if ($result != null)
$result->free();
$db->close();
?>
If you wish to place this order, please enter your information to confirm the order
First Name: |
Last Name: |
Login Name: |
bakeryneworderconfirm.php
Bakery Order ConfirmationBakery Order Confirmation
Thank You for your order. Your order is successfully processed. Order Confirmation number is
<?php@ $db = new mysqli(‘localhost’, ‘root’, ‘’, ‘bakery’);
if (mysqli_connect_errno()) {
echo ‘Error: Could not connect to database. Please try again later.’;
exit;
}
// Insert into Customer table first
$query =“insert into customer values (’”.$_POST[‘first’]."’, ‘".$_POST[‘last’]."’, ‘".$_POST[‘login’]."’);";
//echo $query;
$result = $db->query($query);
if ($result == null)
echo “Insert into customer Failed”;
// Insert into order_items table
$query = “select * from product”;
$result = $db->query($query);
$num_results = $result->num_rows;
$quant = $_POST[‘quantity’];
echo $quant[0];
echo $quant[1];
$totalPrice = 0;
for ($i=0; $i <$num_results; $i++) {
$row = $result->fetch_assoc();
$unitPrice = $row[‘UnitPrice’];
$quant = $_POST[‘quantity’.$i];
$price = $unitPrice * $quant;
$totalPrice += $price;
$orderId = 0;
$query =“insert into order_items values (’”.$row[‘ProductName’]."’, “.$orderId.”, “.$price.”, “.$quant.”)";
echo $query;
}
// Finally Insert into Orders table
$query =“insert into orders values (’”.$_POST[‘last’]."’, “.$orderId.”, “.$totalPrice.”)";
echo $query;
if ($result != null) {
$result->free();
$db->close();
}
?>
UnitPrice float(4,2) not null)
;
insert into Product values
(1,“Chocolate Cake”, 6.99),
(2,“Danish Rings”,5.49),
(3,"Cinnamon Rolls", 3.59),
(4,“Apple Pie”, 3.99);
create table orders(lastName char(20) not null, orderId int Auto_increment primary key, totalPrice float(6,2) not null);
create table order_items(productName char(20), orderId int not null, Price float(6,2) not null, quantity int not null);
create table customer(firstName char(20), lastName char(20), loginName char(20));
I am getting the error (Notice: Undefined index: quantity in C:\wamp\www\bakery\BakeryNewOrderConfirm.php on line 31) in the bakeryneworderconfirm.php
Any help on this is greatly appreciated.