Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder
    Join Date
    Sep 2010
    Location
    London, UK
    Posts
    167
    Thanks
    28
    Thanked 0 Times in 0 Posts

    How do I change a fixed item count on a checkcart page to a user adjustable one?

    I am trying to tweak code that I did not write in a checkcart.php page.

    In the checkcart page the quantity field is not able to be changed and I would like to tweak the code to enable a buyer to change the quantity with an update button added.

    Can someone show me how to do it?

    Here is the code that is in the checkcart.php page, and the quantity area is shown in bold as 'QUANTITY AREA HERE':
    PHP Code:
    <?php
    session_start
    ();
    require(
    "./UserSQL.inc.php");

    $db = new UserSQL($DBName);
    $filename $_GET["filename"];
    $filename explode("/",$filename);
    $count count($filename)-1;
    $filename $filename[$count];
    $catid $db->getcatidbyfilename($filename);
    if(!empty(
    $catid)){
    $sql="update catalog set count=count+1 where catalogid='$catid'";
    $db->update($sql);
    }
    $result $db->getcatalogbyid($catid);
    $catalogname=$result[0]["catalogname"];
    $catalogname=stripslashes($catalogname);
    $title $result[0]["title"];
    $title=stripslashes($title);
    $title=html_entity_decode($title);
    $title=strip_tags($title);
    $description=$result[0]["description"];
    $keywords=$result[0]["keywords"];
    $bodytext stripslashes($result[0]["bodytext"]);
    $bodytext html_entity_decode($bodytext);
    $filepath="./pics/";
    if(!empty(
    $productkey))
    {
     unset(
    $Product[$productkey]);
    session_register("Product");
    $_SESSION["Product"]=$Product;
    }
    ?>

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

    <html>
    <head>
    <title> Checking your order with Gum Paste Flowers by Suzette</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="keywords" content="<?php echo $keywords;?>" />
    <meta name="description" content="<?php echo $description;?>" />

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

    <!--[if gte IE 5.5]>
    <script language="JavaScript" src="dhtml.js" type="text/JavaScript"></script>
    <![endif]-->

    </head>
    <body>
    <table  align="center" width="100%" valign="top" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <!-- Table 1 Row 1 Column 1 -->
            <td valign="top">
        

            <table  align="center" valign="top" width="820" height="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <!-- Table 2 Row 1 Column 1 -->
                        <td width="69" id=table2>                            
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;            
                        </td>
                    <!-- Row 1 Column 2 -->
                        <td id=verticalborder>
                                              &nbsp;                                    
                        </td>
                    <!-- Row 1 Column 3 -->
                        <td id=centralbody>

    <table width="820" height="678" align="center" border="0" cellspacing="0" cellpadding="0">
    <tr height="130"><td align="center" valign="top">
    <div id="logo" ><?php include("header.php"); ?></div>
    </td></tr><tr height="30"><td align="center" valign="top">
    <div id="header">
    <div id="menu"><?php include("topmenu.php"); ?></div>
    </div>
    </td></tr>

    <!-- Start of Central Text/Content -->

    <tr height="450"><td Valign="top">
    <form action="<? print "$PHP_SELF";?>" method="post">
    <table width="100%" align="center" border="0" cellspacing="0" cellpadding="0" bgcolor="#FDFDF0">

    <tr>
    <td colspan="7" align="right"><A HREF="flowers.php"><img src="images/Cont_0.jpg" border="0"></A>&nbsp;&nbsp;</td>
    <td align="right"><a href="checkout.php?<?print"areaid=$areaid&taxid=$taxid";?>"><img src="./images/checkout.jpg" border="0"></a><td></tr>
    <tr><td colspan="8">&nbsp;&nbsp;&nbsp;Country:&nbsp;&nbsp;&nbsp;
    <select name="areaid" onchange="submit()">
    <?
    $areares
    =$db->getarea();
    if(!empty(
    $areares)){
     while(list(
    $key,$val)=each($areares)){
      
    $tempareaid=stripslashes($val["areaid"]);
      
    $temparea=stripslashes($val["area"]);
      if(
    $areaid==$tempareaid){
      print
    "<option value=\"$tempareaid\" selected>$temparea</option>";
      }else{
      print
    "<option value=\"$tempareaid\">$temparea</option>";
      }
     }
    }
    ?>
    </select>
    &nbsp;&nbsp;&nbsp;&nbsp;Location:&nbsp;&nbsp;<select name="taxid" onchange="submit()">
    <?
    $taxres
    =$db->gettax();
    if(!empty(
    $taxres)){
     while(list(
    $key,$val)=each($taxres)){
      
    $temptaxid=stripslashes($val["taxid"]);
      
    $templocation=stripslashes($val["location"]);
      if(
    $taxid==$temptaxid){
      print
    "<option value=\"$temptaxid\" selected>$templocation</option>";
      }else{
      print
    "<option value=\"$temptaxid\">$templocation</option>";
      }
     }
    }
    ?></select>
    </td></tr>
    <?
    if(empty($areaid)){
    $areaid=$areares[0]["areaid"];
    }
    $rate=$db->getratebyid($areaid);
    if(empty(
    $taxid)){
     
    $taxid=$taxres[0]["taxid"];
    }
    $taxratio=$db->gettaxbyid($taxid);
    ?>
    <tr height="35">
    <td width="15%"><center><b>Flower</b></center></td>
    <td width="255"><center><b>Description</b></center></td>
    <td width="115"><center><b>Size/Style</b></center></tdf>
    <td><center><b>Quantity</b></center></td>
    <td><center><b>Price</b></center></td>
    <td width="55"><center><b>Tax</b></center></td>
    <td width="70"><center><b>Sub-<br>Total</b></center></td>
    <td></td></tr>

    /*QUANTITY AREA HERE */

    <?php
    $total
    =0;

    if(
    session_is_registered("Product")){
    foreach (
    $Product as $i => $value){
       
    $productarray=$Product[$i];
       
    $productid=$productarray[0];
          
    $sizeid=$productarray[1];
          
    $quantity=$productarray[2];

       
    $productres=$db->getproductbyid($productid);
       if(!empty(
    $productres)){
       
    $description=stripslashes($productres[0]['description']);
     
    $sizename=stripslashes($productres[0]['sizename']);
     
    $sizename=$sizearray[$sizename];
     
    $picture=stripslashes($productres[0]['picture']);
     
    $smallpic=stripslashes($productres[0]['smallpic']);

       
    $sizeres=$db->getproductsizebyid($sizeid);
       
    $size=stripslashes($sizeres[0]['size']);
       
    $price=stripslashes($sizeres[0]['price']);


       
    $tax=$price*$quantity*$taxratio;
     
    $tax=round($tax,2);
     
    $totalprice=$price*$quantity+$tax;

     
    $total+=$totalprice;

     
    $price=number_format($price2'.''');
     
    $tax=number_format($tax2'.''');
     
    $totalprice=number_format($totalprice2'.''');

     
    ?>
    <tr bgcolor="#FFFFFF">
    <td><center><img src="<? print"$filepath$smallpic";?>" border="0"></center></td>
    <td><center><? print"$description";?></center></td>
    <td><center><? print"$size";?></center></td>
    <td><center><? print"$quantity";?></center></td>
    <td><center><? print"$price";?></center></td>
    <td><center><?print"$tax";?></center></td>
    <td align="right">$<? print"$totalprice";?></td>
    <td width="90"><center><a href="<? print "$PHP_SELF?productkey=$i";?>">Remove</a></center></td></tr>


    <?php
       
    }}
       
    $total+=$rate;
       
    $rate=number_format($rate2'.''');
       
    $total=number_format($total2'.''');
       print
    "<tr>
    <td colspan=\"6\" align=\"right\">Shipping/Packing:<br>
    Total:<br></td>
    <td align=\"right\">$rate<br>$$total<br></td>
    <td></td></tr>"
    ;
       }
    ?>
    <tr><td colspan="8">&nbsp;</td></tr>
    <tr><td colspan="7" align="right"><A HREF="flowers.php"><img src="images/Cont_0.jpg" border="0"></A>&nbsp;&nbsp;</td><td align="right"><a href="checkout.php?areaid=$areaid&taxid=$taxid"><img src="./images/checkout.jpg" border="0"></a></td></tr>
    </table>
    </form>
    </td></tr>
    <tr height="10">
          <td>
        &nbsp;
        </td>
    </tr>
    <tr height="68">
    <td align="center" valign="top">
    <div id="footer"><?php include("footer.php"); ?></div>
    </td></tr>
    </table>
                </td>
                        <td id=verticalborder>
                                              &nbsp;                                    
                        </td>
                        <td width="69" id=table3>                            
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;            
                        </td>            

    </tr>
    </table>
    </td>
    </tr>
    </table>



    <!-- End of footers -->
    <!-- Start of Address Area -->
    <!-- End of Wrapper  -->

    <!-- Start of StatCounter Code -->
    <script type="text/javascript">
    var sc_project=6371968; 
    var sc_invisible=1; 
    var sc_security="5be6e313"; 
    </script>

    <script type="text/javascript"
    src="http://www.statcounter.com/counter/counter.js"></script><noscript><div
    class="statcounter"><a title="drupal analytics"
    href="http://statcounter.com/drupal/" target="_blank"><img
    class="statcounter"
    src="http://c.statcounter.com/6371968/0/5be6e313/1/"
    alt="drupal analytics" ></a></div></noscript>
    <!-- End of StatCounter Code -->

    </body>
    </html>
    Last edited by judgedredd; 05-18-2011 at 03:07 PM.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,525
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    I would expect that the quantity would be changed using a textbox similar to the red part shown below ...

    <tr bgcolor="#FFFFFF">
    <td><center><img src="<? print"$filepath$smallpic";?>" border="0"></center></td>
    <td><center><? print"$description";?></center></td>
    <td><center><? print"$size";?></center></td>
    <td><center><input type="text" name="qty" value="<?=$quantity?>"></center></td>
    <td><center><? print"$price";?></center></td>
    <td><center><?print"$tax";?></center></td>
    <td align="right">$<? print"$totalprice";?></td>


    When displaying the form, the user would be able to adjust qty.
    To affect the price immediately, would require javascripting (or AJAX).
    But, if they changed the quantity and submitted the form, you would
    then take the new quantity value and recalculate.

    It would be nice to see how your form currently works (a working example).


    .
    Last edited by mlseim; 05-18-2011 at 03:58 PM.

  • Users who have thanked mlseim for this post:

    judgedredd (05-18-2011)

  • #3
    Regular Coder
    Join Date
    Sep 2010
    Location
    London, UK
    Posts
    167
    Thanks
    28
    Thanked 0 Times in 0 Posts
    Hi mlseim,

    Thanks for that.

    I do know that in the code there is the ability to remove an item. When an item is removed then the page refreshes immediately with the new list of (reduced) number of items.

    The line where the removal occurs is:

    PHP Code:
    <td width="90"><center><a href="<? print "$PHP_SELF?productkey=$i";?>">Remove</a></center></td></tr>
    So is the update code exactly the same?
    Last edited by judgedredd; 05-18-2011 at 04:12 PM.

  • #4
    Regular Coder
    Join Date
    Sep 2010
    Location
    London, UK
    Posts
    167
    Thanks
    28
    Thanked 0 Times in 0 Posts
    Oops. Forgot to give you the link for the actual site to show you how the form works. Here it is:

    http://www.gumpasteflowersbysuzette.com/flowers.php

    choose some flowers and then proceed to 'View my Shopping'.

  • #5
    Regular Coder
    Join Date
    Sep 2010
    Location
    London, UK
    Posts
    167
    Thanks
    28
    Thanked 0 Times in 0 Posts
    Could I add something like the code below?:

    PHP Code:
      <form name="<?print"$productid";?>" action="<? print"$PHP_SELF";?>" method="post">
      <input type="submit" name="updateproduct" value="Update">
    Not sure how to add the "updateproduct" field to the code. Or is that not needed? I have altered some values here, from the page which lists the products/flowers to reflect what this code is trying to do.

  • #6
    Regular Coder
    Join Date
    Sep 2010
    Location
    London, UK
    Posts
    167
    Thanks
    28
    Thanked 0 Times in 0 Posts
    mlseim,

    If I change the number of items and then go to checkout it does not take the new value. It reverts back to the original value.

  • #7
    Regular Coder
    Join Date
    Sep 2010
    Location
    London, UK
    Posts
    167
    Thanks
    28
    Thanked 0 Times in 0 Posts
    I just found the answer to updating after changing the amount of items in the checkcart page.

    I have to have an 'Update' button which is wrapped in a <form></form>.

    Do you know how to do this?
    Last edited by judgedredd; 05-19-2011 at 02:07 AM.

  • #8
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,525
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    In the link you gave, when I enter a quantity and "add to cart",
    I get a "page not found" error. So, I have not yet seen the page
    where you wish to change the quantity.


    .

  • #9
    Regular Coder
    Join Date
    Sep 2010
    Location
    London, UK
    Posts
    167
    Thanks
    28
    Thanked 0 Times in 0 Posts
    Hi mlseim,

    Thank you!! The website was hacked sometime between yesterday and the 10th May, so what you saw was the result of that.

    If it was not for you I would not have noticed this.

    I am having my hosting company look into this as I write.

    So I will let you know when this has been sorted out.

    Thanks again.

  • #10
    Regular Coder
    Join Date
    Sep 2010
    Location
    London, UK
    Posts
    167
    Thanks
    28
    Thanked 0 Times in 0 Posts
    Hi mlseim,

    The site has been sorted out so all the pages work.

    I have added your little snippet of code and you can see it in operation.

    I have been researching how to reload page with new values and is a bit beyond me because I have to make sense of the code I found. It is not as easy to do as I thought.

  • #11
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,525
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    Various ways of hacking ...

    One might be MySQL injections because you don't sanitize variables
    before using them in your queries:
    http://php.net/manual/en/function.my...ape-string.php

    Another might be directory and file permissions set to 0777 (777).
    They should not be set to that. Perhaps, 744 or 644?
    Depends sort of on your webhost server ... how they set the permissions
    when files are created or updated. Ask your webhost about that.


    .

  • #12
    Regular Coder
    Join Date
    Sep 2010
    Location
    London, UK
    Posts
    167
    Thanks
    28
    Thanked 0 Times in 0 Posts
    Not really sure why I was sent to the page you gave as it did not seem to have anything to do with this update code.

    I found this on some site:

    PHP Code:
    if (isset($_POST['submit'])){
    foreach(
    $_POST as $key => $value){
    $key explode("-",$key);
    $key end($key);
    $key explode("submit"$key);
    $key end($key);

    if(
    $_POST['quantity-'.$key] == 0){
    unset(
    $_SESSION['cart'] [$key]);
    //echo "Unset session";
    }else{
    $_SESSION['cart'][$key]['quantity'] = $value;
    //echo "Updated session";
    }

    }

    But not really sure how to implement it as the
    PHP Code:
    'cart' 
    variable is not in my code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •