Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6122325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:53:08+00:00 2026-05-23T15:53:08+00:00

So i edited my own shop but im having some issues with it, for

  • 0

So i edited my own shop but im having some issues with it, for example it add 2 instead of 1 or it removes 2 instead of 1,

you can see how it looks on http://www.neobotmx.org/test/tienda.php <<< not opwn for the public yet >> thats why its on a test folder

The shop code :

 <?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 && !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;

    }

?>


  <?php 

    if($_SESSION['cart']) { //if the cart isn't empty
        //show the cart
            echo "<table border=\"1\" align=\"center\" padding=\"3\" width=\"70%\">";
            echo "<tr>";
                        //show this information in table cells
                        echo "<td align=\"center\"><strong>Producto</strong></td>";
                        //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 "<td align=\"center\"><strong>Cantidad</strong></td>";
                        echo "<td align=\"center\"><strong>Costo</strong></td>";

                    echo "</tr>";//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 => $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) > 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 "<tr>";
                        //show this information in table cells
                        echo "<td align=\"center\"><strong>$name</strong></td>";
                        //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 "<td align=\"center\"><strong>$quantity </strong><a href=\"$_SERVER[PHP_SELF]?action=remove&id=$product_id\">Borrar</a></td>";
                        echo "<td align=\"center\"><strong>$line_cost</strong></td>";

                    echo "</tr>";

                }

            }

            //show the total
            echo "<tr>";
                echo "<td colspan=\"2\" align=\"right\"><strong>Total</strong></td>";
                echo "<td align=\"right\"><strong>$total</strong></td>";
            echo "</tr>";
            echo "</table>";



    }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)) > 0;
    }
?>
  </p>
<p><strong><a href="tienda.php">Seguir Comprando</a></strong></p>


<?php

and now the display of the books / items / whatever you want.

 <?php
  define('MAX_REC_PER_PAGE', 1);
  $sql = "SELECT id, name, description, price FROM products;";
    $rs = mysql_query("SELECT COUNT(*) FROM products") or die("Imposible Realizar Operacion");
  list($total) = mysql_fetch_row($rs);
  $total_pages = ceil($total / MAX_REC_PER_PAGE);
  $page = intval(@$_GET["page"]); 
  if (0 == $page){
  $page = 1;
  }  
  $start = MAX_REC_PER_PAGE * ($page - 1);
  $max = MAX_REC_PER_PAGE;
  $rs = mysql_query("SELECT id, name, description, price FROM products ORDER BY id 
   ASC LIMIT $start, $max") or die("Imposible Realizar Operacion");
  ?>

  <table width="100%" height="404" border="0" cellpadding="12">
  <?php
  while (list($id, $name, $description, $price) = mysql_fetch_row($rs)) {
  ?>
  <tr>
  <td height="46" align="left" valign="middle"><p><strong> Producto :
      <?= htmlspecialchars($name) ?> 
      </strong>
    </p></td>
  </tr>
  <tr>
  <td height="172" align="left" valign="middle"><p><strong>Descripcion :</strong></p>
    <p>
      <strong>
      <?= htmlspecialchars($description) ?> 

      </strong></p></td>
  </tr>
  <tr>
  <td height="67" align="left" valign="middle"><p><strong>Precio : 
    <?= htmlspecialchars($price) ?> </strong>
  </p></td>
  </tr>
  <tr>
  <td height="109" align="center" valign="middle"><strong><? echo "<a href=\"pedido.php?action=add&id=$id\">Comprar</a>" ?> </strong></td>
  </tr>
  <?php
  }
  ?>
  </table>
  <table border="0" cellpadding="5" align="center">
  <tr>
  <td><strong>Pagina : </strong></td>
  <?php
  for ($i = 1; $i <= $total_pages; $i++) {
  $txt = $i;
  if ($page != $i)
  $txt = "<a href=\"" . $_SERVER["PHP_SELF"] . "?page=$i\">$txt</a>";
  ?>  
  <td align="center"><?= $txt ?></td>
  <?php
  }
  ?>
  </table>

I have no idea where’s the error on it…

Ty for the help 🙂

Obiusly you have to :

<?php session_start();?>
include your database
etc
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:53:09+00:00Added an answer on May 23, 2026 at 3:53 pm

    You have in the style:

    body {
        background-image: url();
    }
    

    which is causing the browser to request the page again, which adds it to the cart again.

    Instead of rendering the cart page, Once the code has modified the cart it should send a redirect to the cart page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edited to Add * I haven't found a solution for this one yet, can
I saved some edited images in my own created directory under my app folder
EDITED: Updated 3/23/09. See rest of post at bottom. I'm still having trouble with
Edited: SOLUTION FOUND. This is strange and not the best solution, but I just
(Edited a lot) I've got some classes with Abstracts Members. The concrete type of
--edited for clarity (hopefully) I have an XML file that looks something like this:
[Edited: After cross-testing on a fresh machine and some additional research, this appears to
I tried this on my own but couldn't get it to work right. Basically
This is just for my own understanding of how concurrency issues work. Let's say
Let's say there is an object TaskList which can be edited and deleted only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.