Hello All,
Iam creating a shopping cart and basing the session content iam adding a add / remove to the product.
First question is that a good away of doing it?
Second would be Iam throwing a error if the $_session doesn't exist for both the session and the 'array_key_exists' Would best way to solve this be by wrapping it iin a if if($_SESSION["cart_products"]) {the code below} else {out put add button}
$out = "
<div class='row'>
<form method='post' action='http://localhost/cart/'>
<div class='medium-4 columns'>
{$room->title} {$room->id}
</div>
<div class='medium-4 columns'>
£{$room_cost_pp} p/p x {$room->room_spaces} guests = £{$room_cost}
</div>
<div class='medium-2 columns'>
<input type='hidden' name='cabin_id' value='{$room->id}' />
<input type='hidden' name='cabin_name' value='{$room->title}'/>
<input type='hidden' name='cabin_cost' value='{$room_cost}'/>
<input type='hidden' name='return_url' value='{$current_url}' />";
$search_array = $_SESSION["cart_products"];
if (array_key_exists($room->id, $search_array)) {
$out.="<input type='hidden' name='remove_code[]'' value='{$room->id}' />
<button type='submit' class='alert button'>Remove Cabin</button>";
}else {
$out.="<input type='hidden' name='type' value='add' />
<button type='submit' class='success button'>Add Cabin</button>";
}
Cheers
Jon