Jump to content

[SOLVED] updating shopping cart quantities.


severndigital

Recommended Posts

I am trying to update quantities for items in a shopping cart that are being added to the form via a while loop. see below. I know I can be simplifying my Db queries, but that is not the focus of my question.

 

 

<?
//this is essentially what is happening.

//first start the table and form
echo '
<form name="scartform" method="post" action="' . $_SERVER['PHP_SELF'] . '">
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="scartborder">
  <tr>
    <td class="scart_headers">Item</td>
    <td class="scart_headers">Desc.</td>
    <td class="scart_headers">Qty</td>
    <td class="scart_headers">Per Piece </td>
    <td class="scart_headers">Total</td>
  </tr>
  <tr>
    <td class="scartborder"><img src="images/spacer.gif" alt="spacer" width="10" height="10"></td>
    <td class="scartborder"><img src="images/spacer.gif" alt="spacer" width="10" height="10"></td>
    <td class="scartborder"><img src="images/spacer.gif" alt="spacer" width="10" height="10"></td>
    <td class="scartborder"><img src="images/spacer.gif" alt="spacer" width="10" height="10"></td>
    <td class="scartborder"><img src="images/spacer.gif" alt="spacer" width="10" height="10"></td>
  </tr>';

//now loop the products into the table

$sql = "SELECT * FROM fnlproducts WHERE dealerid='$dealerid'";

$getcontents = mysql_query($sql);

while($row = mysql_fetch_array($getcontents)){
        $scid = $row['scid'];
        $pid = $row['pid'];
$qty = $row['qty'];
	//get some information about the product.
		$getpinfo = mysql_query("SELECT p_name,p_distrip,p_matrix,p_altprice FROM products WHERE pid='$pid'");
		$prow = mysql_fetch_array($getpinfo);
			$item = $prow['p_name'];
			$distrip = $prow['p_distrip'];
		$price = $prow['p_altprice'];

		$tprice = $qty * $price;
		$tprice = money_format('%i',$tprice);

		$total_price = $tprice + $total_price;

echo '<tr>
    <td class="scartborder"><span class="scitem">' . $item . '</span></td>
    <td class="scartborder"><span class="scitem">' . $distrip . '</td>
    <td class="scartborder"><span class="scitem">
<!-- ####This is the quantity form field. -->
<input name="quantity-' . $scid .'" type="text" id="thisisid" size="5" maxlength="3" value="' . $qty . '"></td>
<! -- ####End quantity form field -->
<td class="scartborder"><span class="scitem">' . $price . '</td>
    <td class="scartborder"><span class="scitem">' . $tprice . '</td>
  </tr>';
}// end while loop.

 

My question is when i submit the new quantites, how to post them? I can't seem to figure this out, because I have no way of knowing what the name of the field will be since I won't know beforehand what the $scid of the item will be.

 

I know the post would be something like this

 

$newquantity = $_POST['nameofqtyfield'];

 

but again, i don't know how to post a field I won't know the name of ahead of time.

 

Any help would be really great. even it means re-doing the query from the ground up.

 

thanks in advance.

Chris

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.