Jump to content

Shopping Cart Print Receipt [UPDATED]

ashraf97

How do i add a show receipt then a print receipt function in my shopping cart system this is so far the coding for it

<!doctype html><html><head><meta charset="utf-8"><title>Products</title><style>*{margin: 0;padding: 0;}table{    border-collapse: collapse;} table, th, td{    border: 2px solid black;}h1{text-align: center;color: white;}header{background-color: #069764;width: 90%;padding: 13px;box-sizing: border-box;margin: 0 auto;}#wrapper{width: 90%;margin: 0 auto;padding: 15px;border: 4px solid black;box-sizing: border-box;}</style><script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?skin=desert"></script></head> <body><body bgcolor="#0069099"><header><h1>Ashraf's Fully Hectic Car Shop</h1></header><div id="wrapper"><br><table><tr>     <td><img src="Ford.jpeg" style="width:110px;height:120px;"><hr><h3>Ford Gt 2015</h3><br><a href="cart.php?addItem=Ford GT 2015">Add to Cart</a></td>        <td><img src="R35.jpg" style="width:100px;height:120px;"><hr><h3>Nissan R35</h3><br><a href="cart.php?addItem=Nissan R35">Add to Cart</a></td>        <td><img src="SP20.jpg" style="width:100px;height:120px;"><hr><h3>SP20</h3><br><a href="cart.php?addItem=SP20">Add to Cart</a></td>    </tr></table></div></body></html> 
<?php session_start();if(isset($_GET['addItem'])){    if(!empty($_SESSION['cart'])){        array_push($_SESSION['cart'], htmlspecialchars($_GET['addItem']));       }else{        $_SESSION['cart'] = array(htmlspecialchars($_GET['addItem']));    }} ?><!doctype html><html><head><meta charset="utf-8"><title>Products</title><script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?skin=desert"></script><style>*{margin: 0;padding: 0;}table{    border-collapse: collapse;} table, th, td{    border: 1px solid black;}h1{text-align: center;color: white;}header{background-color: #069764;width: 90%;padding: 10px;box-sizing: border-box;margin: 0 auto;}#wrapper{width: 90%;margin: 0 auto;padding: 15px;border: 2px solid black;box-sizing: border-box;} </style></head> <body><body bgcolor="#069099"><header><h1>Ashraf's Fully Hectic Car Shop</h1></header><div id="wrapper"><a href="products.php">Go to previous page</a><br><a href="destroy.php">Clear Cart & Return to Previous Page</a><br><br><table>     <?php  $total = 0;if(!empty($_SESSION['cart'])){foreach($_SESSION['cart'] as $product){echo "<tr><td>$product</td><td>";if($product == "Ford GT 2015"){echo '$60000';$total = $total + 60000;}else if($product == "Nissan R35"){echo '$110000';$total = $total + 110000;}else if($product == "SP20"){echo '$9800';$total = $total + 9800;}else{echo '-';}echo "</td></tr>";}}echo '<tr><td><strong>TOTAL</strong></td><td>$' . $total . '</td></tr>'; ?>        </table></div></body></html>
Link to comment
Share on other sites

Link to post
Share on other sites

Uh, add a button that submits a form with a certain variable set, on the php script if the variable is set use your receipt template with a listing of the products, use a print stylesheet that is switched on with javascript or somethin' and there you go.

Link to comment
Share on other sites

Link to post
Share on other sites

Uh, add a button that submits a form with a certain variable set, on the php script if the variable is set use your receipt template with a listing of the products, use a print stylesheet that is switched on with javascript or somethin' and there you go.

so I've made a button on the cart.php called Preview receipt and that form is connected to another form called receipt. php and is that what should have the code of the total and what not?

Link to comment
Share on other sites

Link to post
Share on other sites

need help making a preview receipt with a print function with it? anyone help me? this is my cart code, anyone help me I'm stuck on what to do.

 

<?php session_start();if(isset($_GET['addItem'])){    if(!empty($_SESSION['cart'])){        array_push($_SESSION['cart'], htmlspecialchars($_GET['addItem']));       }else{        $_SESSION['cart'] = array(htmlspecialchars($_GET['addItem']));    }} ?><!doctype html><html><head><meta charset="utf-8"><title>Products</title><style>*{margin: 0;padding: 0;}table{    border-collapse: collapse;} table, th, td{    border: 1px solid black;}h1{text-align: center;color: white;}header{background-color: #069764;width: 90%;padding: 10px;box-sizing: border-box;margin: 0 auto;}#wrapper{width: 90%;margin: 0 auto;padding: 15px;border: 2px solid black;box-sizing: border-box; } </style></head> <body><body bgcolor="#069099"><header><h1>Ashraf's Fully Hectic Car Shop</h1></header><div id="wrapper"><a href="products.php">Go to previous page</a><br><a href="destroy.php">Clear Cart & Return to Previous Page</a><br><br><table>     <?php  $total = 0;if(!empty($_SESSION['cart'])){foreach($_SESSION['cart'] as $product){echo "<tr><td>$product</td><td>";if($product == "Ford GT 2015"){echo '$60000';$total = $total + 60000;}else if($product == "Nissan R35"){echo '$110000';$total = $total + 110000;}else if($product == "SP20"){echo '$9800';$total = $total + 9800;}else{echo '-';}echo "</td></tr>";}}echo '<tr><td><strong>TOTAL</strong></td><td>$' . $total . '</td></tr>'; ?>      </table></div></body></html><h1><button onclick="Receipt.php"()">Preview Receipt </button> </h1>  
Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×