开发者

PHP Shopping Cart Problem

开发者 https://www.devze.com 2023-01-25 10:12 出处:网络
Okay, so I have a shopping cart problem. I\'ve decided to roll out my own cart, which is alot easier than I had expected. BUT, I\'ve run into a problem and cannot for the life of me figure out what t

Okay, so I have a shopping cart problem.

I've decided to roll out my own cart, which is alot easier than I had expected. BUT, I've run into a problem and cannot for the life of me figure out what to do next.

The problem:

After adding products to the cart, the user is taken to a "checkout" page, where they edit the quantities of the i开发者_如何学运维tems they want.

These items are displayed in a table.

How can I get these items with their edited/new values into a PHP variable, and then update the corresponding entries in the database?

The page in question is:

But to actually see stuff in the "checkout" page, you'll need to visit:

http://www.com.au/.php and click on a few prices, and then click "Place Order" link just above the table.

Any help/advice at all would be greatly appreciated.


If I understand you correctly, you just need to add a input variable.

<tr>
    <td>Cool Item</td>
    <td><input type='text' name='items[<?=$product_id;?>]' value='1' /></td>
</tr>

Then check the $_POST['items'] array.

foreach($_POST['items'] as $product_ID=>$quanity) {
    proccessItem($product_ID, $quanity);
}


You will need to use a form that post onto the page to change the values in the database. Another option would be to use an Ajax request if you do not want the page to reload on update.

I would say in this instance you would want add a remove from cart button and a onkeyup event to your quantity box that would then be handled through Ajax.


Your question is not clear, but am answering because you appreciate any help. :-)

Are you using session.

create a session array for keep the selected items

when ever user edit his cart update thats session array.

show items from that array. at last when he check out post data into db from this session array.

i found an error on website

Warning: Invalid argument supplied for foreach() in E:\web\onestopf\checkout.php on line 55

Then on that row count now its 10,20,23. 10,20,30 will be better :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消