Jump to content

Renee2008

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Renee2008's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I'm really frustrated now. I fixed the name property in the form field, but the $cartId[$i] and $productId[$i] still displayed the first number .
  2. Hi DarkWater, would you please make it clear? in which section i'd better to use foreach statement? Thanks
  3. Thanks DarkWater. But the "$_POST['txtQty']" is array. Because I want to allow customer to put different items in the shopping cart and they can update the quantities for different itmes at one time. Following is the statment for your refernce: <td width="75"><input name="txtQty" type="text" id="txtQty[]" size="5" value="<?php echo $ct_qty; ?>" class="box" onKeyUp="checkNumber(this);"> <input name="hidCartId" type="text" value="<?php echo $ct_id; ?>"> <input name="hidProductId" type="text" value="<?php echo $pd_id; ?>"> </td>
  4. " $_POST['txtQty']" means the product quantity that customer wants to update. e.g. If one customer want to buy 4 bags instead of 1, the new "$_POST['txtQty']" will be changed to "4". I just tested statement: echo "$cartId, $productId,$itemQty; "; On the screen, it displayed correctly "91, 53, 4". it's the correct result. But when I tried to change the code to: echo "$cartId[$i], $productId[$i],$itemQty; "; On the screen, it only displayed "9,5,4";
  5. Hi Jahren, sorry for my poor typo. Yes, in the echo statement, I did miss the "$" symbol. And the "$newQty = (int)$itemQty[$i];" just make sure the $newQty will be an integer? And the $newQty doesn't relate to the $cartId[$i]?I dont' know why the $cartId[$i] will only display the first number of the element?
  6. Thanks for you guys quick response. I have pasted the code in the top. By the way, following two lines of code are the form fields which will post the value "hidCartId" and "hidProductId" to the top function. Sorry i'm still a php green hand. Really appreciate. <input name="hidCartId" type="text" value="<?php echo $ct_id; ?>"> <input name="hidProductId" type="text" value="<?php echo $pd_id; ?>">
  7. I am testing some shopping cart in my local computer.But right now I am blocked by array error:I found both the array cartId and array productId only display the first numberof one element e.g. if the cartId=91,it only display "9". and if productId=53, it will only display "5" on the screen. Weird is: if i'm trying to print the whole array list like "echo "$cartId";" it will display the complete the element like "91" or "53". I tried to figure out the root cause but got failed. Anybody can give me some clues? Really appreciate, Renee function updateCart() { $cartId = $_POST['hidCartId']; $productId = $_POST['hidProductId']; $itemQty = $_POST['txtQty']; $numItem = count($itemQty); $numDeleted = 0; $notice = ''; for ($i = 0; $i < $numItem; $i++) { $newQty = (int)$itemQty[$i]; if ($newQty < 1) { // remove this item from shopping cart $test=$cartId[$i]; deleteFromCart($cartId[$i]); $numDeleted += 1; } else { // check current stock $sql = "SELECT pd_name, pd_qty FROM tbl_product WHERE pd_id = {$productId[$i]}"; $result = dbQuery($sql); $row = dbFetchAssoc($result); // I inserted the echo statement here so that I found the $cartId[i] and $productId[i] print out the wrong result echo "$i; $cartId[i];$productId[$i]"; if ($newQty > $row['pd_qty']) { // we only have this much in stock $newQty = $row['pd_qty'];
×
×
  • 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.