How to remove the item from the cart if the quantity is 0? I have included my code below that I am confused about how to implement this on. 0) { $_SESSION['quant'][$x] = $_POST[$quant_id]; } elseif($_POST[$quant_id] == 0) { //HOW DO I REMOVE THE ITEM FROM THE CART IF QUANTITY IS = 0? } else { echo "Quantity must be greater than 0 to purchase."; } } } if(isset($_POST['remove'])) { //HOW DO I REMOVE THE ITEM FROM THE CART IF THE "REMOVE" BUTTON IS CLICKED? } if(isset($_POST['submit_order'])) { header("location: order.php"); } if(!isset($_SESSION['product_id'])) { echo 'The cart is empty!'; } if($_POST['clear_cart']) { session_unset(); echo 'Your cart is empty'; echo 'Continue Shopping'; } $t_open = 'NameEachQtyDeleteTotal'; $t_middle = ''; $t_close = ''; $total = 0; ?> '; $t_middle .= '' .$_SESSION['name'][$x].''; $t_middle .= '$' .$_SESSION['price'][$x].''; $t_middle .= ''; //IF REMOVE IMAGE IS CLICKED ITEM IS REMOVED FROM CART $t_middle .= 'Delete'; //FIX?? $t_middle .= '$' .($_SESSION['price'][$x] * $_SESSION['quant'][$x]).''; $t_middle .= ''; $total += ($_SESSION['price'][$x] * $_SESSION['quant'][$x]); } $t_middle .= 'Grand Total: $'.$total.''; $t = $t_open.$t_middle.$t_close; echo $t; ?> Continue Shopping
How to remove the item from the cart if the quantity is 0? I have included my code below that I am confused about how to implement this on. 0) { $_SESSION['quant'][$x] = $_POST[$quant_id]; } elseif($_POST[$quant_id] == 0) { //HOW DO I REMOVE THE ITEM FROM THE CART IF QUANTITY IS = 0? } else { echo "Quantity must be greater than 0 to purchase."; } } } if(isset($_POST['remove'])) { //HOW DO I REMOVE THE ITEM FROM THE CART IF THE "REMOVE" BUTTON IS CLICKED? } if(isset($_POST['submit_order'])) { header("location: order.php"); } if(!isset($_SESSION['product_id'])) { echo 'The cart is empty!'; } if($_POST['clear_cart']) { session_unset(); echo 'Your cart is empty'; echo 'Continue Shopping'; } $t_open = 'NameEachQtyDeleteTotal'; $t_middle = ''; $t_close = ''; $total = 0; ?> '; $t_middle .= '' .$_SESSION['name'][$x].''; $t_middle .= '$' .$_SESSION['price'][$x].''; $t_middle .= ''; //IF REMOVE IMAGE IS CLICKED ITEM IS REMOVED FROM CART $t_middle .= 'Delete'; //FIX?? $t_middle .= '$' .($_SESSION['price'][$x] * $_SESSION['quant'][$x]).''; $t_middle .= ''; $total += ($_SESSION['price'][$x] * $_SESSION['quant'][$x]); } $t_middle .= 'Grand Total: $'.$total.''; $t = $t_open.$t_middle.$t_close; echo $t; ?> Continue Shopping
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
How to remove the item from the cart if the quantity is 0?
I have included my code below that I am confused about how to implement this on.
<?php
session_start();
$page = 'cart';
//DATABASE CONNECTION INFO
include_once ('includes/database.php');
include_once ('includes/header.php');
if(!isset($_COOKIE['loggedIn']))
{
header("location: login.php");
}
if (isset($_POST['update']))
{
for ($x = 0; $x < sizeof($_SESSION['quant']); $x++)
{
$quant_id = 'quant_'.$x;
if($_POST[$quant_id] > 0)
{
$_SESSION['quant'][$x] = $_POST[$quant_id];
}
elseif($_POST[$quant_id] == 0)
{
//HOW DO I REMOVE THE ITEM FROM THE CART IF QUANTITY IS = 0?
}
else
{
echo "Quantity must be greater than 0 to purchase.";
}
}
}
if(isset($_POST['remove']))
{
//HOW DO I REMOVE THE ITEM FROM THE CART IF THE "REMOVE" BUTTON IS CLICKED?
}
if(isset($_POST['submit_order']))
{
header("location: order.php");
}
if(!isset($_SESSION['product_id']))
{
echo '<h2>The cart is empty!</h2>';
}
if($_POST['clear_cart'])
{
session_unset();
echo '<p>Your cart is empty</p>';
echo '<p><a href="catalog.php" class="button">Continue Shopping</a></p>';
}
$t_open = '<table><tr><th>Name</th><th>Each</th><th>Qty</th><th>Delete</th><th>Total</th></tr>';
$t_middle = '';
$t_close = '</table>';
$total = 0;
?>
<form method ="POST">
<?php
for ($x = 0; $x < sizeof($_SESSION['product_id']); $x++)
{
$t_middle .= '<tr>';
$t_middle .= '<td class="name">' .$_SESSION['name'][$x].'</td>';
$t_middle .= '<td class="each">$' .$_SESSION['price'][$x].'</td>';
$t_middle .= '<td class="qty"><input name="quant_'.$x.'" type="text" value="'.$_SESSION['quant'][$x].'"></input></td>';
//IF REMOVE IMAGE IS CLICKED ITEM IS REMOVED FROM CART
$t_middle .= '<td class="delete"><a href="#" name="remove">Delete</a></td>'; //FIX??
$t_middle .= '<td class="total">$' .($_SESSION['price'][$x] * $_SESSION['quant'][$x]).'</td>';
$t_middle .= '</tr>';
$total += ($_SESSION['price'][$x] * $_SESSION['quant'][$x]);
}
$t_middle .= '<tr><td colspan ="4">Grand Total: </td><td>$'.$total.'</td></tr>';
$t = $t_open.$t_middle.$t_close;
echo $t;
?>
<input name="update" class="button" type="submit" value="Update Cart">
<input name="clear_cart" class="button" type="submit" value="Clear Cart">
<input name="submit_order" class="button" type="submit" value="Submit Order">
<?php
if(isset($_POST['submit_order']))
{
header('location:order.php');
}
?>
<a href="catalog.php" class="button">Continue Shopping</a>
</form>
<?php
include_once ('includes/footer.php');
?>
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education