Hi,
I'm building a very very simple shopping cart script (it's not used for a shopping cart - but the principles are the same) - The first section allows you to add products to the basket - but i'm having trouble deleting them.
I know i'm soooooooo close but i think I need another view , can anyone point out what i'm doing wrong with regards to deleting an item please?
You might want to test this code
Please see the code below
<?php
session_start();
if(empty($_POST)){
?>
<form action="" method="post" name="items" target="_self" id="items">
<input type="submit" name="company" value="MacDonalds"> </form>
<form action="" method="post" name="items" target="_self" id="items"><input type="submit" name="company" value="Apple"></form>
<form action="" method="post" name="items" target="_self" id="items"><input type="submit" name="company" value="Microsoft"> </form>
<?
}
else{
$companies = $_POST['company'];
if(is_array($_SESSION['companies'])){
if(!in_array($companies, $_SESSION['companies'])){
array_push($_SESSION['companies'], $companies);
}
}
else{
$_SESSION['companies'] = array($companies);
}
// count how many entries in the array
$num_elements = count($_SESSION['companies']);
echo "<strong>Franchise Selection</strong><br />";
echo '<table>';
for ($idx = 0; $idx < $num_elements; ++$idx)
{
print <<<BLOCK
<tr>
<td>{$_SESSION['companies'][$idx]}</td>
<td><a href="index.php?SubmitFinal=update&del=$idx">delete</a></td>
</tr>
BLOCK;
}
echo '<tr><td colspan="2" align="center">';
echo '<form action="basket3.php" method="get"><input type="submit" name="Submit" value="Submit"></form>';
echo '</td></tr>';
echo '</table>';
}
print_r($_SESSION);
?>