TheJoey Posted September 13, 2009 Share Posted September 13, 2009 I have a shopping cart that uses sessions to store information. How would i pass on information to product a mini basket to view all items and checkout, if someone could point me in the right direction. <?php session_start(); //////////////// Brand new session - offer login if (! $_SESSION[active]) { $_SESSION[active] = 1; $heading = "Welcome - please log in"; $htmlsay = "Please enter your name <input name=whoareyou>"; } else { //////////////// Name has been entered - store it if (! $_SESSION[uname]) { $_SESSION[uname] = $_REQUEST[whoareyou]; $_SESSION[cart] = array(); } /////////////// Report purchases so far $offering = array ("apple","banana","cherry","damson"); $buy = $_REQUEST[buy]; if ($buy != "") $_SESSION[cart][$buy]++; $heading = "You have ... "; foreach ($offering as $fruit) { if ($_SESSION[cart][$fruit] > 0) { $heading .= $_SESSION[cart][$fruit]." $fruit, "; $npf ++; } } if ($npf < 1) $heading .= " nothing in your shopping basket yet"; $htmlsay = ""; ///////////////// If not checking out, offer more purchases if ($_REQUEST[next] != "checkout") { $heading .= "<BR>Please select a piece of fruit"; foreach ($offering as $fruit) { $htmlsay .= "<input type=radio name=buy value=$fruit> $fruit<BR>"; } $htmlsay .= "<input type=submit name=next value=add>"; $htmlsay .= "<input type=submit name=next value=checkout>"; ///////////// If checking out, clear session //// (Live application would go on to delivery info, etc) } else { $htmlsay = "$_SESSION[uname], Your order is placed. Thank you for shopping with us<BR>"; $htmlsay .= "<input type=submit name=next value=continue>"; session_destroy(); } } //////////// Following is the HTML! ?> <title>Session based shopping cart</title> <body bgcolor=white > <h2>Demonstration of a session</h2> <?php echo $heading;?> <form method=post action="<?php echo $PHP_SELF;?>"> <?php echo $htmlsay;?> </form> </body> Link to comment https://forums.phpfreaks.com/topic/174056-mini-cart/ Share on other sites More sharing options...
TheJoey Posted September 14, 2009 Author Share Posted September 14, 2009 I have a shopping cart that uses sessions to store information. How would i pass on information to product a mini basket to view all items and checkout, if someone could point me in the right direction. <?php session_start(); //////////////// Brand new session - offer login if (! $_SESSION[active]) { $_SESSION[active] = 1; $heading = "Welcome - please log in"; $htmlsay = "Please enter your name <input name=whoareyou>"; } else { //////////////// Name has been entered - store it if (! $_SESSION[uname]) { $_SESSION[uname] = $_REQUEST[whoareyou]; $_SESSION[cart] = array(); } /////////////// Report purchases so far $offering = array ("apple","banana","cherry","damson"); $buy = $_REQUEST[buy]; if ($buy != "") $_SESSION[cart][$buy]++; $heading = "You have ... "; foreach ($offering as $fruit) { if ($_SESSION[cart][$fruit] > 0) { $heading .= $_SESSION[cart][$fruit]." $fruit, "; $npf ++; } } if ($npf < 1) $heading .= " nothing in your shopping basket yet"; $htmlsay = ""; ///////////////// If not checking out, offer more purchases if ($_REQUEST[next] != "checkout") { $heading .= "<BR>Please select a piece of fruit"; foreach ($offering as $fruit) { $htmlsay .= "<input type=radio name=buy value=$fruit> $fruit<BR>"; } $htmlsay .= "<input type=submit name=next value=add>"; $htmlsay .= "<input type=submit name=next value=checkout>"; ///////////// If checking out, clear session //// (Live application would go on to delivery info, etc) } else { $htmlsay = "$_SESSION[uname], Your order is placed. Thank you for shopping with us<BR>"; $htmlsay .= "<input type=submit name=next value=continue>"; session_destroy(); } } //////////// Following is the HTML! ?> <title>Session based shopping cart</title> <body bgcolor=white > <h2>Demonstration of a session</h2> <?php echo $heading;?> <form method=post action="<?php echo $PHP_SELF;?>"> <?php echo $htmlsay;?> </form> </body> Link to comment https://forums.phpfreaks.com/topic/174056-mini-cart/#findComment-918305 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.