Print/echo $_SESSION['cart'] to sql
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/6643928/session-cart-adding-2-or-2-problem">SESSION Cart adding 2 + or -2 problem</a>  </p>
</blockquote>



<p>How can i Print the content " thats the result of the echos from the buying botton "</p>

<pre><code>&lt;?php

    $product_id = $_GET[id];     //the product id from the URL 
    $action     = $_GET[action]; //the action from the URL 

    //if there is an product_id and that product_id doesn't exist display an error message
    if($product_id &amp;&amp; !productExists($product_id)) {
        die("Error. Product Doesn't Exist");
    }

    switch($action) {   //decide what to do 

        case "add":
            $_SESSION['cart'][$product_id]++; //add one to the quantity of the product with id $product_id 
        break;

        case "remove":
            $_SESSION['cart'][$product_id]--; //remove one from the quantity of the product with id $product_id 
            if($_SESSION['cart'][$product_id] == 0) unset($_SESSION['cart'][$product_id]); //if the quantity is zero, remove it completely (using the 'unset' function) - otherwise is will show zero, then -1, -2 etc when the user keeps removing items. 
        break;

        case "empty":
            unset($_SESSION['cart']); //unset the whole cart, i.e. empty the cart. 
        break;

    }

?&gt;


  &lt;?php 

    if($_SESSION['cart']) { //if the cart isn't empty
        //show the cart
            echo "&lt;table border=\"1\" align=\"center\" padding=\"3\" width=\"70%\"&gt;";
            echo "&lt;tr&gt;";
                        //show this information in table cells
                        echo "&lt;td align=\"center\"&gt;&lt;strong&gt;Producto&lt;/strong&gt;&lt;/td&gt;";
                        //along with a 'remove' link next to the quantity - which links to this page, but with an action of remove, and the id of the current product
                        echo "&lt;td align=\"center\"&gt;&lt;strong&gt;Cantidad&lt;/strong&gt;&lt;/td&gt;";
                        echo "&lt;td align=\"center\"&gt;&lt;strong&gt;Costo&lt;/strong&gt;&lt;/td&gt;";

                    echo "&lt;/tr&gt;";//format the cart using a HTML table

            //iterate through the cart, the $product_id is the key and $quantity is the value
            foreach($_SESSION['cart'] as $product_id =&gt; $quantity) {    

                //get the name, description and price from the database - this will depend on your database implementation.
                //use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection
                $sql = sprintf("SELECT name, description, price FROM products WHERE id = %d;",
                                $product_id); 

                $result = mysql_query($sql);

                //Only display the row if there is a product (though there should always be as we have already checked)
                if(mysql_num_rows($result) &gt; 0) {

                    list($name, $description, $price) = mysql_fetch_row($result);

                    $line_cost = $price * $quantity;        //work out the line cost
                    $total = $total + $line_cost;           //add to the total cost

                        echo "&lt;tr&gt;";
                        //show this information in table cells
                        echo "&lt;td align=\"center\"&gt;&lt;strong&gt;$name&lt;/strong&gt;&lt;/td&gt;";
                        //along with a 'remove' link next to the quantity - which links to this page, but with an action of remove, and the id of the current product
                        echo "&lt;td align=\"center\"&gt;&lt;strong&gt;$quantity &lt;/strong&gt;&lt;a href=\"$_SERVER[PHP_SELF]?action=remove&amp;id=$product_id\"&gt;Borrar&lt;/a&gt;&lt;/td&gt;";
                        echo "&lt;td align=\"center\"&gt;&lt;strong&gt;$line_cost&lt;/strong&gt;&lt;/td&gt;";

                    echo "&lt;/tr&gt;";

                }

            }

            //show the total
            echo "&lt;tr&gt;";
                echo "&lt;td colspan=\"2\" align=\"right\"&gt;&lt;strong&gt;Total&lt;/strong&gt;&lt;/td&gt;";
                echo "&lt;td align=\"right\"&gt;&lt;strong&gt;$total&lt;/strong&gt;&lt;/td&gt;";
            echo "&lt;/tr&gt;";
            echo "&lt;/table&gt;";



    }else{
        //otherwise tell the user they have no items in their cart
        echo "No tiene articulos en compra.";

    }

    //function to check if a product exists
    function productExists($product_id) {
            //use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection
            $sql = sprintf("SELECT * FROM products WHERE id = %d;",
                            $product_id); 

            return mysql_num_rows(mysql_query($sql)) &gt; 0;
    }
?&gt;
  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="tienda.php"&gt;Seguir Comprando&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;


&lt;?php
</code></pre>

<p>This its the code of the web page " Products " in [http://www.neobotmx.org/test/pedido.php][1]</p>

<p>if you click <strong>seguir comprando</strong> ( Continue buying ) you can <strong>comprar</strong> ( buy ), "x" number of products, the result of them will be display'd in <strong>pedido.php</strong> .</p>

<p>Now, what i want to do, its create a botton or a link ( whatever dosnt really matter ) that when its click'd the <strong>table</strong> display'd on <strong>pedido.php</strong> will be paste on a txt table inside the database ( sql database ), or print an order in the database, so i can do, another webpage that will display your current order, and if its pay'd or not.</p>

<p>in other words, i want to know wich user its buying, and what is he buying</p>

<p>i hope i made my self clear this time</p>

<p>i also have the</p>

<pre><code>$_SESSION['name']
</code></pre>

<p>that prints the current user browsing the site if hes logged in.</p>

<p><strong>Rephrase the question :</strong></p>

<p>How can i extract the table on the </p>

<p><strong>picture : <a href="http://i.stack.imgur.com/X5FSB.png" rel="nofollow">http://i.stack.imgur.com/X5FSB.png</a></strong></p>

<p>To a table database in my sqldatabase, that will contain producto, cantidad, costo, and total wich are a result of the code :</p>

<pre><code>&lt;?php 

    if($_SESSION['cart']) { //if the cart isn't empty
        //show the cart
            echo "&lt;table border=\"1\" align=\"center\" padding=\"3\" width=\"70%\"&gt;";
            echo "&lt;tr&gt;";
                        //show this information in table cells
                        echo "&lt;td align=\"center\"&gt;&lt;strong&gt;Producto&lt;/strong&gt;&lt;/td&gt;";
                        //along with a 'remove' link next to the quantity - which links to this page, but with an action of remove, and the id of the current product
                        echo "&lt;td align=\"center\"&gt;&lt;strong&gt;Cantidad&lt;/strong&gt;&lt;/td&gt;";
                        echo "&lt;td align=\"center\"&gt;&lt;strong&gt;Costo&lt;/strong&gt;&lt;/td&gt;";

                    echo "&lt;/tr&gt;";//format the cart using a HTML table

            //iterate through the cart, the $product_id is the key and $quantity is the value
            foreach($_SESSION['cart'] as $product_id =&gt; $quantity) {    

                //get the name, description and price from the database - this will depend on your database implementation.
                //use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection
                $sql = sprintf("SELECT name, description, price FROM products WHERE id = %d;",
                                $product_id); 

                $result = mysql_query($sql);

                //Only display the row if there is a product (though there should always be as we have already checked)
                if(mysql_num_rows($result) &gt; 0) {

                    list($name, $description, $price) = mysql_fetch_row($result);

                    $line_cost = $price * $quantity;        //work out the line cost
                    $total = $total + $line_cost;           //add to the total cost

                        echo "&lt;tr&gt;";
                        //show this information in table cells
                        echo "&lt;td align=\"center\"&gt;&lt;strong&gt;$name&lt;/strong&gt;&lt;/td&gt;";
                        //along with a 'remove' link next to the quantity - which links to this page, but with an action of remove, and the id of the current product
                        echo "&lt;td align=\"center\"&gt;&lt;strong&gt;$quantity &lt;/strong&gt;&lt;a href=\"$_SERVER[PHP_SELF]?action=remove&amp;id=$product_id\"&gt;Borrar&lt;/a&gt;&lt;/td&gt;";
                        echo "&lt;td align=\"center\"&gt;&lt;strong&gt;$line_cost&lt;/strong&gt;&lt;/td&gt;";

                    echo "&lt;/tr&gt;";

                }

            }

            //show the total
            echo "&lt;tr&gt;";
                echo "&lt;td colspan=\"2\" align=\"right\"&gt;&lt;strong&gt;Total&lt;/strong&gt;&lt;/td&gt;";
                echo "&lt;td align=\"right\"&gt;&lt;strong&gt;$total&lt;/strong&gt;&lt;/td&gt;";
            echo "&lt;/tr&gt;";
            echo "&lt;/table&gt;";



    }else{
        //otherwise tell the user they have no items in their cart
        echo "No tiene articulos en compra.";

    }

    //function to check if a product exists
    function productExists($product_id) {
            //use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection
            $sql = sprintf("SELECT * FROM products WHERE id = %d;",
                            $product_id); 

            return mysql_num_rows(mysql_query($sql)) &gt; 0;
    }
?&gt;
</code></pre>

<p>so i can add it in an order lets say :</p>

<p>table orders # will show
that information  ( see picture )</p>
