Update cart quantity only updating one product
I am trying to use a single button to update all my cart quantity and it's not working
I have added the product to cart via sessions, display products from cart now all I'm trying to do is to update the quantity and it's not updating
if(isset($_POST["updates"])) {
if(isset($_SESSION["shopping_cart"])) {
$pid=$_POST['proid'];
$qty =$_POST['quantity'];
foreach ($_SESSION['shopping_cart'] as $key => $value) {
if ($value['item_id'] == $_POST['proid']) {
$_SESSION['shopping_cart'][$key]['item_qty'] = $_POST['quantity'];
}
}
$_SESSION['shopping_cart'] = array_values($_SESSION['shopping_cart']);
header('Refresh:0');
}
}
@RiggsFolly here is the print result
Array (
[0] => Array (
[item_id] => 24
[item_name] => something
[item_price] => 800
[item_qty] => 1
)
[1] => Array (
[item_id] => 26
[item_name] => Fishly
[item_price] => 450
[item_qty] =>
)
)
php session
|
show 3 more comments
I am trying to use a single button to update all my cart quantity and it's not working
I have added the product to cart via sessions, display products from cart now all I'm trying to do is to update the quantity and it's not updating
if(isset($_POST["updates"])) {
if(isset($_SESSION["shopping_cart"])) {
$pid=$_POST['proid'];
$qty =$_POST['quantity'];
foreach ($_SESSION['shopping_cart'] as $key => $value) {
if ($value['item_id'] == $_POST['proid']) {
$_SESSION['shopping_cart'][$key]['item_qty'] = $_POST['quantity'];
}
}
$_SESSION['shopping_cart'] = array_values($_SESSION['shopping_cart']);
header('Refresh:0');
}
}
@RiggsFolly here is the print result
Array (
[0] => Array (
[item_id] => 24
[item_name] => something
[item_price] => 800
[item_qty] => 1
)
[1] => Array (
[item_id] => 26
[item_name] => Fishly
[item_price] => 450
[item_qty] =>
)
)
php session
Some sensible code indentation would be a good idea. It helps us read the code and more importantly it will help you debug your code Take a quick look at a coding standard for your own benefit. You may be asked to amend this code in a few weeks/months and you will thank me in the end.
– RiggsFolly
yesterday
Try addingprint_r($SESSION['shopping_cart']);before and after this line$_SESSION['shopping_cart'] = array_values($_SESSION['shopping_cart']);that may tell you the problem
– RiggsFolly
yesterday
And it would be useful if you pasted the results of those 2print_r()statements into your question if that does not help you
– RiggsFolly
yesterday
tried that not getting any print out
– Asquare Kabiesi
yesterday
then write the output to a file
– RiggsFolly
yesterday
|
show 3 more comments
I am trying to use a single button to update all my cart quantity and it's not working
I have added the product to cart via sessions, display products from cart now all I'm trying to do is to update the quantity and it's not updating
if(isset($_POST["updates"])) {
if(isset($_SESSION["shopping_cart"])) {
$pid=$_POST['proid'];
$qty =$_POST['quantity'];
foreach ($_SESSION['shopping_cart'] as $key => $value) {
if ($value['item_id'] == $_POST['proid']) {
$_SESSION['shopping_cart'][$key]['item_qty'] = $_POST['quantity'];
}
}
$_SESSION['shopping_cart'] = array_values($_SESSION['shopping_cart']);
header('Refresh:0');
}
}
@RiggsFolly here is the print result
Array (
[0] => Array (
[item_id] => 24
[item_name] => something
[item_price] => 800
[item_qty] => 1
)
[1] => Array (
[item_id] => 26
[item_name] => Fishly
[item_price] => 450
[item_qty] =>
)
)
php session
I am trying to use a single button to update all my cart quantity and it's not working
I have added the product to cart via sessions, display products from cart now all I'm trying to do is to update the quantity and it's not updating
if(isset($_POST["updates"])) {
if(isset($_SESSION["shopping_cart"])) {
$pid=$_POST['proid'];
$qty =$_POST['quantity'];
foreach ($_SESSION['shopping_cart'] as $key => $value) {
if ($value['item_id'] == $_POST['proid']) {
$_SESSION['shopping_cart'][$key]['item_qty'] = $_POST['quantity'];
}
}
$_SESSION['shopping_cart'] = array_values($_SESSION['shopping_cart']);
header('Refresh:0');
}
}
@RiggsFolly here is the print result
Array (
[0] => Array (
[item_id] => 24
[item_name] => something
[item_price] => 800
[item_qty] => 1
)
[1] => Array (
[item_id] => 26
[item_name] => Fishly
[item_price] => 450
[item_qty] =>
)
)
php session
php session
edited yesterday
RiggsFolly
70.3k1864109
70.3k1864109
asked yesterday
Asquare KabiesiAsquare Kabiesi
101
101
Some sensible code indentation would be a good idea. It helps us read the code and more importantly it will help you debug your code Take a quick look at a coding standard for your own benefit. You may be asked to amend this code in a few weeks/months and you will thank me in the end.
– RiggsFolly
yesterday
Try addingprint_r($SESSION['shopping_cart']);before and after this line$_SESSION['shopping_cart'] = array_values($_SESSION['shopping_cart']);that may tell you the problem
– RiggsFolly
yesterday
And it would be useful if you pasted the results of those 2print_r()statements into your question if that does not help you
– RiggsFolly
yesterday
tried that not getting any print out
– Asquare Kabiesi
yesterday
then write the output to a file
– RiggsFolly
yesterday
|
show 3 more comments
Some sensible code indentation would be a good idea. It helps us read the code and more importantly it will help you debug your code Take a quick look at a coding standard for your own benefit. You may be asked to amend this code in a few weeks/months and you will thank me in the end.
– RiggsFolly
yesterday
Try addingprint_r($SESSION['shopping_cart']);before and after this line$_SESSION['shopping_cart'] = array_values($_SESSION['shopping_cart']);that may tell you the problem
– RiggsFolly
yesterday
And it would be useful if you pasted the results of those 2print_r()statements into your question if that does not help you
– RiggsFolly
yesterday
tried that not getting any print out
– Asquare Kabiesi
yesterday
then write the output to a file
– RiggsFolly
yesterday
Some sensible code indentation would be a good idea. It helps us read the code and more importantly it will help you debug your code Take a quick look at a coding standard for your own benefit. You may be asked to amend this code in a few weeks/months and you will thank me in the end.
– RiggsFolly
yesterday
Some sensible code indentation would be a good idea. It helps us read the code and more importantly it will help you debug your code Take a quick look at a coding standard for your own benefit. You may be asked to amend this code in a few weeks/months and you will thank me in the end.
– RiggsFolly
yesterday
Try adding
print_r($SESSION['shopping_cart']); before and after this line $_SESSION['shopping_cart'] = array_values($_SESSION['shopping_cart']); that may tell you the problem– RiggsFolly
yesterday
Try adding
print_r($SESSION['shopping_cart']); before and after this line $_SESSION['shopping_cart'] = array_values($_SESSION['shopping_cart']); that may tell you the problem– RiggsFolly
yesterday
And it would be useful if you pasted the results of those 2
print_r() statements into your question if that does not help you– RiggsFolly
yesterday
And it would be useful if you pasted the results of those 2
print_r() statements into your question if that does not help you– RiggsFolly
yesterday
tried that not getting any print out
– Asquare Kabiesi
yesterday
tried that not getting any print out
– Asquare Kabiesi
yesterday
then write the output to a file
– RiggsFolly
yesterday
then write the output to a file
– RiggsFolly
yesterday
|
show 3 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54251422%2fupdate-cart-quantity-only-updating-one-product%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54251422%2fupdate-cart-quantity-only-updating-one-product%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Some sensible code indentation would be a good idea. It helps us read the code and more importantly it will help you debug your code Take a quick look at a coding standard for your own benefit. You may be asked to amend this code in a few weeks/months and you will thank me in the end.
– RiggsFolly
yesterday
Try adding
print_r($SESSION['shopping_cart']);before and after this line$_SESSION['shopping_cart'] = array_values($_SESSION['shopping_cart']);that may tell you the problem– RiggsFolly
yesterday
And it would be useful if you pasted the results of those 2
print_r()statements into your question if that does not help you– RiggsFolly
yesterday
tried that not getting any print out
– Asquare Kabiesi
yesterday
then write the output to a file
– RiggsFolly
yesterday