Jump to content

Problem With Session


Accolade

Recommended Posts

I am adding items to my cart.php using an add increment case statement.

 

 

case "add":
if (isset($_SESSION['cart'][$comic_id])) {
$_SESSION['cart'][$comic_id]++;
} else {
$_SESSION['cart'][$comic_id] = 1;}

 

My items are presented into an HTML table in the cart.php. I just want to then re-call specific variables from the array in the checkout.php so the customer can confirm the order total along with their personal details. I can only seem to carry the last row over using SESSION variable.

 

e.g.

 

$_SESSION['totalnameqty']=$name . " " . $qty . " " . $total;

 

I want to call all of the rows that exist in the cart.php HTML table.

 

 

 

cart.php:

 

if (isset($_SESSION['cart'][$comic_id])){

echo "<table border=\"0\" padding=\"10\" width=\"80%\">";
echo "<td colspan=\"1\" align=\"left\"><a href=\"title.php\">Continue Shopping</a></div>";
echo "<td colspan=\"6\" align=\"right\"><a href=\"$_SERVER[php_SELF]?action=empty\" onclick=\"return confirm('Crystal Fusion: Are you sure you wish to empty your cart?');\">Empty Cart</a></td>"; 
echo "<tr height=\"20px\">";
echo "<tr height=\"20px\">";
echo "<td align=center>Image</td><td align=center>Title</td><td align=center>Description</td><td colspan=3 align=center>Copies (+/-)</td><td align=center>Price</td>";
echo "<tr height=\"20px\">";


foreach($_SESSION['cart'] as $comic_id => $qty) {

$sql = sprintf("SELECT title, description, cost, image_thumbnail
FROM comic
WHERE comic_id = %d;",$comic_id);

$result = mysql_query($sql);

if(mysql_num_rows($result) > 0) {

list($name, $description, $price, $image_thumbnail) = mysql_fetch_row($result);


$cost = $price * $qty;
$total = $total + $cost;

$cost = number_format($cost,2);
$total = number_format($total,2);
$description = substr($description, 0, 250);

echo "<br><tr>";
echo "<td width=\"10px\" align=\"center\"><img height=100 align=center src=\"$image_thumbnail\">";
echo "<td align=\"center\">$name</td>";
echo "<td width=\"40%\" align=\"center\">$description...<a href=comic_dyn.php?comic_id=$comic_id>More Info</td>";
echo "<td width=\"30px\" align=\"center\"><a href=\"$_SERVER[php_SELF]?action=add&comic_id=$comic_id\">+<br></a><td align=\"center\">$qty <td width=\"20px\" align=\"center\"><a href=\"$_SERVER[php_SELF]?action=remove&comic_id=$comic_id\">-</a></td>";
echo "<td align=\"right\">$$cost</td>";
echo "</tr>";
}

}

echo "<br><tr><tr height=100px>";
echo "<td><td><td colspan=\"4\" align=\"right\">Total:</td>";
echo "<td width=\"60px\" align=\"right\">$$total</td>";
echo "<tr><td colspan=\"7\" align=\"right\"><a href=\"checkout_html.php\">Proceed to Checkout</a>";
echo "<tr height=\"50px\">";
echo "</table>";
}else{

echo "Your cart is currently empty.";
echo "<br><br><td colspan=\"1\" align=\"left\"><a href=\"title.php\">Continue Shopping</a></div>";

}

Edited by Accolade
Link to comment
Share on other sites

Im not sure how to call all the rows from the HTML table / array on the next page using SESSION?

 

When I use:

 

$_SESSION['totalnameqty']=$name . " " . $qty . " " . $total;

 

...I only get the last entry entered into the array returned, rather than all of them.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.