Can someone help me out with this code:
I am sending values via a form to a session array but it is not storing the values, so everytime I click the submit button it is supposed to increment but it is not doing that.
This is the form:
<form method="post" action="">
<input name="Title" type="hidden" value="$5 Donation With Shipping" />
<input name="SerialNum" type="hidden" value="5DollarDonationWS" />
<input name="Price" type="hidden" value="5.00" />
<input name="Shipping1" type="hidden" value="1.00" />
<input name="Shipping2" type="hidden" value="0.50" />
<input name="cmd" type="hidden" id="cmd" value="1" />
<input type="submit" name="Submit" value="Add To Cart" />
</form>
and this is the shopping cart script:
<?php
session_start();
$_SESSION['cart'] = array(
"title" => $_POST['title'],
"price" => $_POST['price'],
"author" => $_POST['author'],
"qty" => $_POST['cmd']);
// Check To See If Cart Exists, And Set Count Accordingly
$new = "";
if(isset($_SESSION['cart']))
{
$_SESSION['cart']++;
}else{
$_SESSION['cart'] = 1;
}
foreach( $_SESSION['cart'] as $key =>$value)
{
echo '<table border ="0" width ="100%" cellspacing = "0"><tr><th bgcolor="#cccccc">' . $key . '</th><tr><td>' . $value . '</td></tr></table>';
echo $_SESSION['title'];
}
?>
Can someone help me please
Form using session
Moderator: General Moderators