Dorkmind Posted November 17, 2014 Share Posted November 17, 2014 Hi everyone i made a shopping cart using PHP and MYSQL table. I am kind of an amateur in php and i would like to have an online store, so the basic problem is i have a website and a Shopping Cart, but i don't know what to do, so when a buyer presses buy now, the content of shopping cart will be sent to my email, so i would know what he bought. So can you tell me how to implement a button BUY NOW that will if pressed send me a content of shopping cart straight to my email.Here is the code. I have a table called products in my mysql database. <?php if(isset($_POST['submit'])){ foreach ($_POST['quantity'] as $key => $val) { if ($val==0) { unset ($_SESSION['cart'][$key]); } else { $_SESSION['cart'][$key]['quantity']=$val; } } } ?> <h1> Cart </h1> <form method="post" action="index.php?page=cart"> <table> <tr> <th>Name</th> <th>Quantity</th> <th>Price</th> <th>All Price </th> </tr> <?php $sql="SELECT * FROM products WHERE product_id IN ("; foreach($_SESSION['cart'] as $id => $value) { $sql.=$id.","; } $sql=substr($sql, 0, -1).") ORDER BY name ASC"; $query=mysql_query($sql); $totalprice=0; while($row=mysql_fetch_array($query)) { $subtotal=$_SESSION['cart'][$row['product_id']]['quantity']*$row['price']; $totalprice+=$subtotal; ?> <tr> <td><?php echo $row['name'] ?></td> <td><input type="text" name="quantity[<?php echo $row['product_id']?>]" size="5" value="<?php echo $_SESSION['cart'][$row['product_id']]['quantity'] ?>"/></td> <td><?php echo $row['price']?>€</td> <td><?php echo $_SESSION['cart'][$row['product_id']]['quantity']*$row['price']?>€</td> </tr> <?php } ?> <tr> <td> To Pay: <?php echo $totalprice ?></td> </table> <br/><button type="submit" name="submit"> Refresh</button> </form> <p> To remove product set to 0.</p> Link to comment https://forums.phpfreaks.com/topic/292519-shopping-cart-input-email/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.