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

05-18-2011, 03:04 PM
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':

$db = new UserSQL($DBName);
$filename = $_GET["filename"];
$filename = explode("/",$filename);
$count = count($filename)-1;
$filename = $filename[$count];
$catid = $db->getcatidbyfilename($filename);
$sql="update catalog set count=count+1 where catalogid='$catid'";
$result = $db->getcatalogbyid($catid);
$title = $result[0]["title"];
$bodytext = stripslashes($result[0]["bodytext"]);
$bodytext = html_entity_decode($bodytext);

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<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>

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

<table align="center" valign="top" width="820" height="100%" border="0" cellspacing="0" cellpadding="0">
<!-- Table 2 Row 1 Column 1 -->
<td width="69" id=table2>
<!-- Row 1 Column 2 -->
<td id=verticalborder>
<!-- 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>

<!-- 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">

<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()">
print"<option value=\"$tempareaid\" selected>$temparea</option>";
print"<option value=\"$tempareaid\">$temparea</option>";
&nbsp;&nbsp;&nbsp;&nbsp;Location:&nbsp;&nbsp;<select name="taxid" onchange="submit()">
print"<option value=\"$temptaxid\" selected>$templocation</option>";
print"<option value=\"$temptaxid\">$templocation</option>";
<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 width="55"><center><b>Tax</b></center></td>
<td width="70"><center><b>Sub-<br>Total</b></center></td>



foreach ($Product as $i => $value){





$price=number_format($price, 2, '.', '');
$tax=number_format($tax, 2, '.', '');
$totalprice=number_format($totalprice, 2, '.', '');

<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 align="right">$<? print"$totalprice";?></td>
<td width="90"><center><a href="<? print "$PHP_SELF?productkey=$i";?>">Remove</a></center></td></tr>

$rate=number_format($rate, 2, '.', '');
$total=number_format($total, 2, '.', '');
<td colspan=\"6\" align=\"right\">Shipping/Packing:<br>
<td align=\"right\">$rate<br>$$total<br></td>
<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>
<tr height="10">
<tr height="68">
<td align="center" valign="top">
<div id="footer"><?php include("footer.php"); ?></div>
<td id=verticalborder>
<td width="69" id=table3>


<!-- 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 type="text/javascript"
class="statcounter"><a title="drupal analytics"
href="http://statcounter.com/drupal/" target="_blank"><img
alt="drupal analytics" ></a></div></noscript>
<!-- End of StatCounter Code -->


05-18-2011, 03:53 PM
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 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).


05-18-2011, 04:03 PM
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:

<td width="90"><center><a href="<? print "$PHP_SELF?productkey=$i";?>">Remove</a></center></td></tr>So is the update code exactly the same?

05-18-2011, 04:07 PM
Oops. Forgot to give you the link for the actual site to show you how the form works. Here it is:


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

05-18-2011, 04:24 PM
Could I add something like the code below?:

<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.

05-18-2011, 05:44 PM

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.

05-18-2011, 08:49 PM
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?

05-18-2011, 10:28 PM
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.


05-18-2011, 10:49 PM
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.

05-19-2011, 02:07 AM
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.

05-19-2011, 03:41 AM
Various ways of hacking ...

One might be MySQL injections because you don't sanitize variables
before using them in your queries:

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.


05-19-2011, 04:01 AM
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:

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";
$_SESSION['cart'][$key]['quantity'] = $value;
//echo "Updated session";

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