/    Sign up×
Community /Pin to ProfileBookmark

Duration Select Menu in Shopping Cart

Good Day

I am creating my first php shopping cart and have been struggling to get the duration select menu to work. Below is the code I am working on. If anyone could please point out were I am going wrong or see anything I have missed it will be greatly appreciated. I have been able to use the select menu in the shopping cart but when there is more then one product in the cart it takes the same price of the first product added to the cart.

[CODE]This is php part telling it what to do…..[/CODE]

[CODE]<?php
$duration = “”;
$price_to_adjust = “”;
if (isset($_POST[‘price_to_adjust’]) && $_POST[‘price_to_adjust’] != “”) {
// execute some code
$price_to_adjust = $_POST[‘price_to_adjust’];
$duration = $_POST[‘duration’];
foreach ($_SESSION[“cart_array”] as $each_item) {
$item_id = $each_item[‘item_id’];
$sql = mysql_query(“SELECT * FROM products WHERE id=’$item_id'”);
while ($row = mysql_fetch_array($sql)) {
$price = $row[“price”];
$price2 = $row[“price2”];
$price3 = $row[“price3”];
$price4 = $row[“price4”];
}
if ($duration == “price”) { $duration = $price; }
if ($duration == “price2”) { $duration = $price2; }
if ($duration == “price3”) { $duration = $price3; }
if ($duration == “price4”) { $duration = $price4; }

$i = 0;
foreach ($_SESSION[“cart_array”] as $each_item) {
$i++;
while (list($key, $value) = each($each_item)) {
if ($key == “item_id” && $value == $price_to_adjust) {
$price_value = array(“price” => $price, “price2” => $price2, “price3” => $price3, “price4” => $price4);
// That item is in cart already so let’s adjust its quantity using array_splice()
array_merge_recursive($each_item, $price_value);
} // close if condition
} // close while loop
}
}
}
?>[/CODE]

[B]Here is the select menu that is outputting to the cart….[/B]

[CODE]$cartOutput .= ‘<td><form class=”form” action=”cart.php” method=”POST”>
<select name=”duration”>
<option value=”price”>1 Day</option>
<option value=”price2″>2 Days</option>
<option value=”price3″>3 Days</option>
<option value=”price4″>4-7 Days</option>
</select>
<input name=”changeBtn’ . $item_id . ‘” type=”submit” value=”Update” />
<input type=”hidden” name=”price_to_adjust” value=”‘ . $item_id . ‘”/>
</form></td>’;[/CODE]

Thanks in advance for assisting

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @Pixcy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...