Jump to content

How to allow a user to change the quantity of a product in a shopping cart?


Recommended Posts

 

 

 

 

Hi everyone ???,

 

Im very new to php and mysql and this is my first ever demo website that Im building. To keep the long story short, what I really need help with is that below is a copy of my shopping cart script, I want my user to able to change the quantity of the product that they have added to the shopping cart once they look into their shopping cart. I dont mind if a example can be shown, so that I can understand how Im surpose to create or add the code to my shopping cart code.

 

Thank you

Callisto11

 

 

My shopping cart code:

 

 

<?php

session_start();      //at the top of all pages. sessions it stores the data about the user in the web server.

                      //the session stores session variables for each user,when a session is started the client

    //is given a session identifier

 

if (isset($_SESSION['cart'])) {

?>

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title></title>

<link rel="stylesheet" type="text/css" href="style.css" />

<style type="text/css">

<!--

.style1 {color: #000000}

.style7 {

font-size: 12px;

color: #000000;

}

.style8 {

font-size: 12px;

font-weight: bold;

color: #000000;

}

.style12 {

font-size: 14px;

color: #000000;

}

.style19 {font-size: 14px; color: #000000; font-weight: bold; }

-->

</style>

</head>

<body>

<div id="top_menu"></div>

<div id="main_content">

<div id="top_banner">

    <a href="index.html"><img src="images/roar.jpg" width="391" height="130" alt="home" title="logo" border="0" class="logo" /></a>    </div>

   

 

 

   

  <div >

    <div class="title style1">

      <p><strong>Shopping Cart</strong></p>

    </div>

<div class="content_text">

  <table width="40%" border="1" bordercolor="black" bgcolor="">

            <tr>

              <th width="5%"> <span class="style7">STYLE NUMBER</span></th>

              <th width="6%"> <span class="style7">DETAILS</span></th>

              <th width="6%"> <span class="style8">QUANTITY</span></th>

              <th width="7%"> <span class="style8">SIZE </span></th>

              <th width="7%"> <span class="style8">PRICE (per cartoon) </span></th>

              <th width="8%"> -</th>

              <?php

      foreach ($_SESSION['cart'] as $key => $general_cartoon) {

    ?>

            </tr>

            <tr>

              <td><span class="style19"><?php echo $_SESSION['cart'][$key] ['cartoon_id']; ?></span></td>

              <td><span class="style19"><?php echo $_SESSION['cart'][$key] ['title']; ?></span></td>

              <td><span class="style19"><?php echo $_SESSION['cart'][$key] ['quantity'];?></span></td>

              <td><span class="style19"><?php echo $_SESSION['cart'][$key] ['size'];?></span></td>

              <td><span class="style19"><?php echo $_SESSION['cart'][$key] ['fee'];?></span></td>

              <?php $quantity =$_SESSION['cart'][$key]['quantity'];?>

              <td><a href="removefromcart.php?cartoon_id=<?php echo $_SESSION['cart'][$key]['cartoon_id'];?>&location=<?php echo $_SERVER['PHP_SELF'];?>">[REMOVE]</a></td>

    </tr>

 

            <?php }?>

          </table>

  <p>

            <?php }

    else { ?>

No cartoon chosen yet

<?php }

  ?>

</p>

  <p> </p>

  <form action="rmgallery.php" method="get">

    <input name="back" type="submit" value="BACK TO GALLERY" title=" Takes you back to the gallery page."/>

      </form>

  <form action= "checkoutlogin.php" method="get">

    <input nane= "get" type="submit" value="GENERAL ORDER" title="A general order will allow you to purchase the cartoons in your shopping cart." />

      </form>

  <form action="questionform.php" method="get">

    <input name="get" type="submit" value="PERSONAL ORDER" title="A personal order will allow you to give a description of details you would like in your cartoon." />

      </form>

         

  <p>  </p>

  <p> </p>

    </div>

        <div class="content_text"></div>

     

        <div class="title"></div>

<div class="content_text"><br />

  <br />

      </div>

well, this actually depends on your application logic

 

you can use up and down arrows to increase or decrease your quantity or a text field to type the quantity and then update their cart, and those containing the value zero, are removed from the cart.

 

using the arrows you could use a link with the a query like:

 

<a href="updatecart.php?customer=56&item=3&quantity=3">increase quantity</a>

<a href="updatecart.php?customer=56&item=3&quantity=1">decrease quantity</a>

 

updatecart.php would then validate, filter the input and execute a query along the lines of:

 

update cart set quantity = '$quantity' where item = '$item' and customer = '$customer'

 

something along these lines

 

or with the text field:

 

<input type="hidden" name="customer" value="56" />

<input type="text" name="3" value="3" />

 

in your php:

 

get all items for the customers cart, go over all items and see if the id exists in the $_POST variable, if so update the quantity set in value

To ignace,

 

If I went with your second choice, of a text field, would i apply the example you gave to my above code (shopping cart).

Also what do you mean by 56 and 3 in the example you gave (the text example).

 

 

 

 

Thank you

Callisto11

(P.s: Im quite slow in understanding things)

 

 

 

 

Hi everyone ???,

 

Im very new to php and mysql and this is my first ever demo website that Im building. To keep the long story short, what I really need help with is that below is a copy of my shopping cart script, I want my user to able to change the quantity of the product that they have added to the shopping cart once they look into their shopping cart. I dont mind if a example can be shown, so that I can understand how Im surpose to create or add the code to my shopping cart code.

 

Thank you

Callisto11

 

 

My shopping cart code:

 

 

<?php

session_start();      //at the top of all pages. sessions it stores the data about the user in the web server.

                       //the session stores session variables for each user,when a session is started the client

    //is given a session identifier

 

if (isset($_SESSION['cart'])) {

?>

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title></title>

<link rel="stylesheet" type="text/css" href="style.css" />

<style type="text/css">

<!--

.style1 {color: #000000}

.style7 {

font-size: 12px;

color: #000000;

}

.style8 {

font-size: 12px;

font-weight: bold;

color: #000000;

}

.style12 {

font-size: 14px;

color: #000000;

}

.style19 {font-size: 14px; color: #000000; font-weight: bold; }

-->

</style>

</head>

<body>

<div id="top_menu"></div>

<div id="main_content">

<div id="top_banner">

    <a href="index.html"><img src="images/roar.jpg" width="391" height="130" alt="home" title="logo" border="0" class="logo" /></a>    </div>

   

 

 

   

  <div >

      <div class="title style1">

        <p><strong>Shopping Cart</strong></p>

      </div>

<div class="content_text">

  <table width="40%" border="1" bordercolor="black" bgcolor="">

            <tr>

              <th width="5%"> <span class="style7">STYLE NUMBER</span></th>

              <th width="6%"> <span class="style7">DETAILS</span></th>

              <th width="6%"> <span class="style8">QUANTITY</span></th>

              <th width="7%"> <span class="style8">SIZE </span></th>

              <th width="7%"> <span class="style8">PRICE (per cartoon) </span></th>

              <th width="8%"> -</th>

              <?php

      foreach ($_SESSION['cart'] as $key => $general_cartoon) {

    ?>

            </tr>

            <tr>

              <td><span class="style19"><?php echo $_SESSION['cart'][$key] ['cartoon_id']; ?></span></td>

              <td><span class="style19"><?php echo $_SESSION['cart'][$key] ['title']; ?></span></td>

              <td><span class="style19"><?php echo $_SESSION['cart'][$key] ['quantity'];?></span></td>

              <td><span class="style19"><?php echo $_SESSION['cart'][$key] ['size'];?></span></td>

              <td><span class="style19"><?php echo $_SESSION['cart'][$key] ['fee'];?></span></td>

              <?php $quantity =$_SESSION['cart'][$key]['quantity'];?>

              <td><a href="removefromcart.php?cartoon_id=<?php echo $_SESSION['cart'][$key]['cartoon_id'];?>&location=<?php echo $_SERVER['PHP_SELF'];?>">[REMOVE]</a></td>

    </tr>

 

            <?php }?>

          </table>

  <p>

            <?php }

    else { ?>

No cartoon chosen yet

<?php }

   ?>

</p>

  <p> </p>

  <form action="rmgallery.php" method="get">

    <input name="back" type="submit" value="BACK TO GALLERY" title=" Takes you back to the gallery page."/>

      </form>

  <form action= "checkoutlogin.php" method="get">

    <input nane= "get" type="submit" value="GENERAL ORDER" title="A general order will allow you to purchase the cartoons in your shopping cart." />

      </form>

  <form action="questionform.php" method="get">

    <input name="get" type="submit" value="PERSONAL ORDER" title="A personal order will allow you to give a description of details you would like in your cartoon." />

      </form>

         

  <p>  </p>

  <p> </p>

    </div>

        <div class="content_text"></div>

       

        <div class="title"></div>

<div class="content_text"><br />

  <br />

      </div>

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.