Jump to content

Shopping Cart input => email


Dorkmind

Recommended Posts

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>
Edited by Dorkmind
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.