简体   繁体   English

PHP购物车问题

[英]PHP Shopping Cart Problem

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 items 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? 如何将这些项目及其编辑/新值放入PHP变量中,然后更新数据库中的相应条目?

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. http://www.com.au/.php并单击一些价格,然后单击表上方的“下订单”链接。

Any help/advice at all would be greatly appreciated. 任何帮助/建议都将不胜感激。

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. 如果您不希望页面在更新时重新加载,另一种选择是使用Ajax请求。

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. 我想说在这种情况下,您希望将“从购物车中删除”按钮和onkeyup事件添加到数量框中,然后通过Ajax处理。

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. 然后检查$ _POST ['items']数组。

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

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. 最后,当他从该会话数组中将数据发布到db中时。

i found an error on website 我在网站上发现错误

Warning: Invalid argument supplied for foreach() in E:\\web\\onestopf\\checkout.php on line 55 警告:第55行的E:\\ web \\ onestopf \\ checkout.php中为foreach()提供了无效的参数

Then on that row count now its 10,20,23. 然后在该行上现在数为10、20、23。 10,20,30 will be better :-) 10,20,30会更好:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM