Hi,
I'm writting a very basic "Add to Cart" script - the code is below in 2 parts - can anyone see any problems as to why the variables are not being displayed on the 2nd page? - Also for an added bonus - if someone could figure this out - would you know how to utilize the "Unset" function so a "Delete from cart" - button can be displayed nxt to each result?
If I am going about this the wrong way or can offer me advice I would appreciated.
Page1
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<form method="post" action="basket.php" name="test">
<p>
<input type="checkbox" name="check1" value="Company 1">
<input type="checkbox" name="check2" value="Company 2">
<input type="checkbox" name="check3" value="Company 3">
<input type="checkbox" name="check4" value="Company 4">
<input type="checkbox" name="check5" value="Company 5">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>
Page2
<?php
// start the session
session_start();
header("Cache-control: private"); //IE 6 Fix
echo "<strong>Franchise Selection</strong><br />";
// Get the user's input from the form
$name = $_POST['name'];
// Register session key with the value
$_SESSION['name'] = $name;
// Display the sssion information:
// Get the user's input from the form
if(isset($_POST['check1'])) {
$_SESSION['check'][] = $_POST['check1'];
}
if(isset($_POST['check2'])) {
$_SESSION['check'][] = $_POST['check2'];
}
if(isset($_POST['check3'])) {
$_SESSION['check'][] = $_POST['check3'];
}
if(isset($_POST['check4'])) {
$_SESSION['check'][] = $_POST['check4'];
}
if(isset($_POST['check5'])) {
$_SESSION['check'][] = $_POST['check5'];
}
// Display the sssion information:
$num_elements = count ($_SESSION);
// count how many entries in the array
//
echo "<form method='post' action='basket2.php' name='test1'>";
for ($check = 0; $check < $num_elements; ++$check){
echo ("$_SESSION[$check]");
echo "<input type='checkbox' name='$_SESSION[$idx]' value='$_SESSION[$idx]'><br>";
}
echo "<input type='submit' name='Submit' value='Submit'>";
echo "</form>";
//echo $_SESSION['check'];
echo $num_elements;
?>
Welcome to my website <strong><? echo $_SESSION['name']; ?></strong>!<br />
Let's see what happens on the <a href="page3.php">next page.</a><br /><br />
Thank you.