Jump to content

Need help with updating quantity field in a form inside a shopping cart, pls.


callisto11

Recommended Posts

Hi everyone,

Im finding it hard to make this form work (i've hightlight out the problem in green) what I want is, for a user to be able to update the quantity field of the item they insert into the shopping. So once they have inserted the new amount, they should be able to press update quantity button and it changes it.

 

Thank you

Calliso

(Im very new to php )

 

 

 

      <form action="update_item" method="get">

          <input type="hidden" name="action" value="update_item" />

  <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><input type="text" size="2" name="quantity" value="<?php echo $_SESSION['cart'][$key] ['quantity']; ?>"/></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>

       

          <input name="update" type="submit" value="UPDATE QUANTITIES" title=" Updates the quantities of cartoons in the shopping cart"/>

          </form>

Link to comment
Share on other sites

Is update_item suppose to be update_item.php?  Also, in update_item file, are you using a switch condition to control the action?

If so, I would do this:

 

<form action="update_item.php?action=Update Item" method="post">

 

Then on the update_item page, do this:

 

if(array_key_exists('action', $_GET))// check and grab the variable from the URL

{

     $action = $_GET['action'];

}

 

if(array_key_exists('quantity', $_POST))

{

     $qty = $_POST['quantity'];

}

 

 

Then the switch would be:

 

switch($action)

{

     case 'Update Item':

     

    Your logic goes here such as the UPDATE mysql code....

    break;

}

 

Hope this helps you out.

 

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.