mindapolis Posted November 8, 2011 Author Share Posted November 8, 2011 I have a question about this code. In the section where it 's finding out if the user has added an item it says if(isset($_POST['quantity'] && isset($_POST['id'] in my code id is really product_title and is coming from and is coming from a database. Is it okay to substitute product_title for id? Quote Link to comment https://forums.phpfreaks.com/topic/248595-understanding-sessions/page/2/#findComment-1286095 Share on other sites More sharing options...
xyph Posted November 8, 2011 Share Posted November 8, 2011 Of course! But be consistent. Change the name of the hidden field to product_title as well. Quote Link to comment https://forums.phpfreaks.com/topic/248595-understanding-sessions/page/2/#findComment-1286100 Share on other sites More sharing options...
mindapolis Posted November 8, 2011 Author Share Posted November 8, 2011 okay, I thought that would be right but just wanted to make sure. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/248595-understanding-sessions/page/2/#findComment-1286103 Share on other sites More sharing options...
mindapolis Posted November 8, 2011 Author Share Posted November 8, 2011 Now it 's saying Warning: Invalid argument supplied for foreach() in /home/content/a/u/n/auntievics/html/test/checkOut.php on line 357 concerning this Code foreach($_SESSION['cart'] as $product_title => $quantity) { echo "<li>$product_title $quantity</li>"; } Quote Link to comment https://forums.phpfreaks.com/topic/248595-understanding-sessions/page/2/#findComment-1286107 Share on other sites More sharing options...
Drummin Posted November 8, 2011 Share Posted November 8, 2011 I may me incorrect, but if you are now going with xyph's example, using multiple forms for products, also understand that this script is using ONE page. You are creating the variable $cart from $_SESSION['cart'] and adding items and quantity for each product... HOWEVER you are not updating your session after adding these items so when you get the session on a different page, the session items are not showing. In my humble opinion I would say to update the session by adding these lines. if( isset($cart[$id]) ) // If so, add quantity to it. (int) forces $id to be returned as an integer. $cart[$id] += (int) $quantity; $_SESSION['cart']=$cart;// ADDED LINE else // Otherwise, set it to the quantity $cart[$id] = (int) $quantity; $_SESSION['cart']=$cart;// ADDED LINE // Destroy the reference to $cart to avoid acidentally screwing with it elsewhere in the script Quote Link to comment https://forums.phpfreaks.com/topic/248595-understanding-sessions/page/2/#findComment-1286118 Share on other sites More sharing options...
Drummin Posted November 8, 2011 Share Posted November 8, 2011 I am also unsure about the use of the ampersand on this line. What does it do? $cart = &$_SESSION['cart']; Quote Link to comment https://forums.phpfreaks.com/topic/248595-understanding-sessions/page/2/#findComment-1286121 Share on other sites More sharing options...
trq Posted November 8, 2011 Share Posted November 8, 2011 See http://php.net/references Quote Link to comment https://forums.phpfreaks.com/topic/248595-understanding-sessions/page/2/#findComment-1286138 Share on other sites More sharing options...
Drummin Posted November 8, 2011 Share Posted November 8, 2011 So by reference in the case of the code we're looking at, does the session get updated by updating the variable $cart? Or do we need to use $_SESSION['cart']=$cart; after making any changes to $cart. Quote Link to comment https://forums.phpfreaks.com/topic/248595-understanding-sessions/page/2/#findComment-1286198 Share on other sites More sharing options...
mindapolis Posted November 8, 2011 Author Share Posted November 8, 2011 I am really sorry. I'm really confused now. What do I put where? Quote Link to comment https://forums.phpfreaks.com/topic/248595-understanding-sessions/page/2/#findComment-1286201 Share on other sites More sharing options...
Drummin Posted November 8, 2011 Share Posted November 8, 2011 See my earlier post that has the lines $_SESSION['cart']=$cart; added to what you're working with. Maybe re-posting the code you are currently testing would be good as well, so we're talking about the same thing. Quote Link to comment https://forums.phpfreaks.com/topic/248595-understanding-sessions/page/2/#findComment-1286202 Share on other sites More sharing options...
mindapolis Posted November 8, 2011 Author Share Posted November 8, 2011 thanks so much for the help! I greatly appreciate it! <?php session_start(); if(isset($_POST['empty']) || isset($_SESSION['cart'])) $_SESSION['cart'] = array(); //if a cart is clear or doesn'does not exist yet if(isset($_POST['quantity']) && isset($_POST['product_title'])) { $product_title = $_POST['product_title']; $quantity = $_POST['quantity']; $_SESSION['carr']; $cart = $S_SESSION['cart']; // We will store the item and quantity in the array. $array[item] = quantity // Check if the item is already in the cart if( isset($cart[$id]) ) // If so, add quantity to it. (int) forces $id to be returned as an integer. $cart[$product_title] += (int) $quantity; else // Otherwise, set it to the quantity $cart[$product_title] = (int) $quantity; // Destroy the reference to $cart to avoid acidentally screwing with it elsewhere in the script unset( $cart ); } require_once("functions.php"); DatabaseConnection(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>ordering doggy treats</title> <link href="doggyTreats.css" rel="stylesheet" type="text/css" /> <style type="text/css"> #order { margin-right: auto; margin-left: auto; } .orderRow{ padding-bottom: 50px; } h2 { text-align: center; } </style> </head> <body> <?php logo(); navBar(); ?> <form action="" method="post" name="checkOut"> <table id="order"> <tr class="orderRow"> <td> First name:<br /> <input name="fname" type="text" size="10" maxlength="15" /></td> <td>Last name: <br /> <input name="lname" type="text" size="15" maxlength="30" /></td> <td> Address: <br /> <input name="address" type="text" size="30" /></td> </tr> <tr> <tr class = "orderRow"> <td> City: <br /> <input name="city " type="text" size="15" maxlength="20" /> </td> <td> State: <br /> <select name = "state"> <option selected value ="Please choose a state"/> Please choose a state</option> <option value = "AL" />AL</option> <option value = "AK" />AK</option> <option value = "AR" />AR</option> <option value = "AZ" />AZ <option value = "CA" />CA <option value = "CO" />CO <option value = "CT" />CT <option value = "DE" />DE <option value = "DC" />DC <option value = "FL" />FL <option value = "GA" />GA <option value = "HI" />HI <option value = "IA" />IA <option value = "ID" />ID <option value = "IL" />IL <option value = "IN" />IN <option value = "KS" />KS <option value = "KY" />KY <option value = "LA" />LA <option value = "MA" />MA <option value = "ME" />ME <option value = "MD" />MD <option value = "MI" />MI <option value = "MN" />MN <option value = "MO" />MO <option value = "MS" />MS <option value = "MT" />MT <option value = "NC" />NC <option value = "ND" />ND <option value = "NE" />NE <option value = "NH" />NH <option value = "NJ" />NJ <option value = "NM" />NM <option value = "OH" />OH <option value = "OK" />OK <option value = "OR" />OR <option value = "PA" />PA <option value = "RI" />RI <option value = "SC" />SC <option value = "SD" />SD <option value = "TN" />TN <option value = "TX" />TX <option value = "UT" />UT <option value = "VA" />VA <option value = "VT" />VT <option value = "WA" />WA <option value = "WI" />WI <option value = "WV" />WV <option value = "WY" />WY </select> </td> <td> Zip Code:<br /> <input name="zipcode" type="text" size="5" maxlength="5" /> </td> </tr> <tr class = "orderRow"> <td> Phone <br /> Please include area code <br /> <input name="phone" type="text" size="13" maxlength="13" /> </td> <td> Fax:<br /> <input name="" type="text" size="13" maxlength="13" /> </td> <td> Email: <br /> <input name="email " type="text" size="15" maxlength="30" /> </td> </tr> <tr class = "orderRow"> <td> Please choose method of payment: <br /> Check <input name="check " type="radio" value="Check " /> Money Order <input name="money " type="radio" value="Money order " /><br />PayPal<input name="paypal" type="radio" value="Paypal" /> </td> </tr> <tr> <td colspan = "6"> <h2> Pet Information </h2></td> </tr> <tr> <td> Name: <br /> <input name="petName" type="text" size="10" maxlength="20" /> </td> <td> Age: <br /> <select name="age"> <?php for ($age =1; $age <=20; $age ++) { print "<option value=\"age\"> $age</option>"; } ?> </select> </td> <td> Breed:<br /> <select name = "breed"> <option selected value ="Please choose a breed"/> Please choose a breed <option value = "I don't know" />I don't know <option value = "Affernpincher" />Affernpincher <option value = "Afghan Hound" />Afghan Hound <option value = "Airedale Terrier" /> Airedale Terrior <option value = "Akita" /> Akita <option value = "Alaskan Malamute" /> Alaskan Malamute <option value = "Standard American Eskimo Dog"/> Standard American Eskimo Dog <option value = "Miniature American Eskimo Dog"/>Miniature American Eskimo Dog <option value = "Toy American Eskimo Dog"/> Toy American Eskimo Dog <option value = "American Foxhound" /> American Foxhound <option value = "American Staffordshire Terrier" /> American Staffordshhire Terrier <option value = "American Water Spaniel" /> American Water Spaniel <option value = "Australian Shepherd Dog"/> Anatolian Shepherd Dog <option value = "Australian Cattle Dog"/> Australian Cattle Dog <option value = "Australian Shepherd"/> Australian Shepherd <option value = "Australian Terrier" /> Australia Terrier <option value = "Basenji" /> Basenji <option value = "Basset Hound" /> Basset Hound <option value = "Beagle" /> Beagle <option value = "Bearded Collie" /> Bearded Collie <option value = "Beauceron" /> Beauceron <option value = "Bedington Terrier"/> Bedington Terrier <option value = "Belgin Malinois"/> Belgin Malinois <option value = "Belgian Sheepdog"/> Belgian Sheepdog <option value = "Belgian Tervuren"/> Belgian Tervuren <option value = "Bernese Mountain Dog"/> Bernese Mountain Dog <option value = "Bichon Frise"/> Bichon Frise <option value = "Black and Tan Greyhound" /> Black and Tan Greyhound <option value = "Black Russian Terrier" /> Black Russian Terrier <option value = "Bloodhoung" /> Bloodhound <option value = "Border Collie" /> Border Collie <option value = "Border Terrier"/> Border Terrier <option value = "Borzoi"/> Borzoi <option value = "Boston Terrier"/> Boston Terrier <option value = "Bouvier des Flandres"/> Bouvier des Flandres <option value = "Boxer"/> Boxer <option value = "Briard"/> Briard <option value = "Brittany" /> Brittany <option value = "Brussels Griffon" /> Brussels Griffon <option value = "Bulldog" /> Bulldog <option value = "Bullmastiff" /> Bullmasttiff <option value = "Bull Terrier" /> Bull Terrier <option value = "Cairn Terrier" /> Cairn Terrier <option value = "Canaan Dog" /> Canaan Dog <option value = "Cardigan Welsh Corgi" /> Cardigan Welsh Corgi <option value = "Cavalier King Charles Spaniel" />Cavalier King Charles Spaniel <option value = "Chesepeake Bay Retriever" />Chesapeake Bay Retriever <option value = "Chilauhua" /> Chilauhua <option value = "Chinese Created" /> Chinese Crested <option value = "Chinese Shar-Pei" /> Chinese Shar-Pei <option value = "Chow Chow" /> Chow Chow <option value = "Clumber Spaniel" /> Clumber Spaniel <option value = "Cocker Spaniel" /> Cocker Spaniel <option value = "Collie" /> Collie <option value = "Curly-Coated Retrieve" /> Curly-Coated Retriever <option value = "Dachshound" /> Dachshund <option value = "Dalmation" /> Dalmation <option value = "Dandle Dimonnt" /> Dandie Dinmont Terrier <option value = "Doberman Pincher" /> Doberman Pincher <option value = "Dogue de Bordeaux" /> Dogue de Bordeaux <option value = "English Cocker Spaniel" /> English Cocker Spaniel <option value = "English Foxhound" /> English Foxhound <option value = "English Setter" /> English Setter <option value = "English Springer" /> English Springer <option value = "English Toy Spaniel" /> English Toy Spaniel <option value = "Field Spaniel" /> Field Spaniel <option value = "Finnish Spitz" /> Finnish Spitz <option value = "Flat-Coated Retriever" /> Flat-Coated Retriever <option value = "French Bulldog" /> French Bulldog <option value = "German Shepherd Dog" /> German Shepherd Dog <option value = "German Shorthaired Pointer"/>German Shorthaired Pointer <option value = "German Wirehaired Pointer" /> German Wirehaired Pointer <option value = "Giant Schnauzer" /> Giant Schnauzer <option value = "Glen of Imaal Terrier" /> Glen of Imaal Terrier <option value = "Golden Retriever" /> Golden Retriever <option value = "Gorden Setter" /> Gorden Setter <option value = "Great Dane" /> Great Dane <option value = "Greater Swiss Mountain Dog" /> Greater Swiss Mountain Dog <option value = "Great Pyrenees" /> Great Pyrenees <option value = "Greyhound" /> Greyhound <option value = "Harrier" /> Harrier <option value = "Havanese" /> Havanese <option value = "Ibizen Hound" /> Ibizen Hound <option value = "Irish Setter" /> Irish Setter <option value = "Irish Terrier" /> Irish Terrier <option value = "Irish Water Spaniel" /> Irish Water Spaniel <option value = "Irish Wolfhound" /> Irish Wolfhound <option value = "Italian Greyhound" /> Italian Greyhound <option value = "Jack Russell Terrier" /> Jack Russell Terrier <option value = "Japanese Chin" /> Japanese Chin <option value = "Keeshound" /> Keeshound <option value = "Kerry Blue TErrier" /> Kerry Blue Terrier <option value = "Komondor" /> Komondor <option value = "Kuvasz" /> Kuvasz <option value = "Labradar Retriever" /> Labrador Retriever <option value = "Lakeland Terrier" /> Lakeland Terrier <option value = "Lhasa Apso" /> Lhasa Apso <option value = "Lowchen" /> Lowchen <option value = "Maltese" /> Maltese <option value = "Standard Manchester Terrier" /> Standard Manchester Terrier <option value = "Mastiff" /> Mastiff <option value = "Miniature Bull Terrier" /> Miniature Bull Terrier <option value = "Miniature Pinche" /> Miniature Pinscher <option value = "Miniature Poodle" /> Miniature Poodle <option value = "Miniature Schnauzer" />Miniature Schnauzer <option value = "Mutt" />Mutt <option value = "Neopolitan Mastiff" />Neopolitan Mastiff <option value = "Newfoundland " /> Newfoundland <option value = "Newfolk Terrier" />Norfolk Terrier <option value = "Norwegian Elkhound" /> Norwegian Elkhound <option value = "Norwich Terrier" /> Norwich Terrier <option value = "Nova Scotia Duck Tolling Retriever" /> Nova Scotia Duck Tolling Retriever <option value = "Old English Sheepdog" />Old English Sheepdog <option value = "Otterhound" /> Otterhound <option value = "Papillon" />Papillon <option value = "Parson Russell Terrier" /> Parson Russell Terrier <option value = "Pekingese" />Pekingese <option value = "Pembroke Welsh Corgi" />Pembroke Welsh Corgi <option value = "Petit Basset Griffon Vendeen" />Petit Basset Griffon Vendeen <option value = "Pharch Hound" />Pharoh Hound <option value = "Plott" /> Plott <option value = "Pointer" /> Pointer <option value = "Polish Lowland Sheepdog" />Polish Lowland sheepdog <option value = "Pomeranian" /> Pomeranian <option value = "Portuguese Water Dog" />Portuguese Water Dog <option value = "Pug" />Pug <option value = "Pull" />Puli <option value = "Rhodesian Ridgeback" />Rhodesian Ridgeback <option value = "Rottweiler" />Rottweiler <option value = "ASaint Bernard" /> Saint Bernard <option value = "Saluki" /> Saluki <option value = "Samoyed" />Samoyed <option value = "Schipperke" />Schipperke <option value = "Scottish Doverhound" />Scottish Deerhound <option value = "Scottish Terrier" />Scottish Terrier <option value = "Sealyham Terrier" />Sealyham Terrier <option value = "Shetland Sheepdog" />Shetland Sheepdog <option value = "Shiba Inu" />Shiba Inu <option value = "Shih Tzu" />Shih Tzu <option value = "Siberian Husky" />Siberian Husky <option value = "Silky Terrier" />Silky Terrier <option value = "Skye Terrier" />Skye Terrier <option value = "Smooth Fox Terrier" />Smooth Fox Terrier <option value = "Soft Coated Wheaten Terrier" />Soft Coated wheaten Terrier <option value = "Spinone Italiano" />Spinone Italiano <option value = "Staffordshire Bull Terrier" />Staffordshire Bull Terrier <option value = "Standard Poodle" />Standard Poodle <option value = "Standard Schnauer" /> Standard Schnauzer <option value = "Suseex Spaniel" />Sussex Spaniel <option value = "Swedish Vallhound" />Swedish Vallhund <option value = "Tibertan Mastiff" />Tibetan Mastiff <option value = "Tibertan Spaniel" />Tibetan Spaniel <option value = "Tibetan Terrier" />Tibetan Terrier <option value = "Toy Fox Terrier" />Toy Fox Terrier <option value = "Toy Manchester Terrier" />Toy Manchester Terrier <option value = "Toy Poodle" />Toy Poodle <option value = "Vizela" />Vizela <option value = "Weimaraner" />Weimaraner <option value = "Welsh Springer Spaniel" />Welsh Springer Spaniel <option value = "Welsh Terrier" />Welsh Terrier <option value = "West Highland White Terrier" />West Highland White Terrier <option value = "Whippet" />Whippet <option value = "Wire Fox Terrier" />Wire Fox Terrier <option value = "Wirehaired Pointing Griffon" />Wirehaired Pointing Griffon <option value = "Yorkshire Terrier" />Yorkshire Terrier </select> </td> </tr> <tr> <td>Nutritional Needs:</td> <td><textarea name="nutritionalNeeds" cols="17" rows="5"></textarea> </td> </tr> <tr> <td>Special Instructions</td> <td><textarea name="specialInstructions" cols="17" rows="5"></textarea></td> </tr> <tr> <td colspan = "6"><h2>Order Information</h2></td> </tr> <tr> <ul> <?php foreach($_SESSION['cart'] as $product_title => $quantity) { echo "<li>$product_title $quantity</li>"; } ?> </ul> </tr> <tr> <td> <input name="Submit" type="submit" value="Order Treats!" /></td><td><input name="reset" type="submit" value="Cancel Order" /> </td> </tr> </table> </form> </body> </html> [code] Quote Link to comment https://forums.phpfreaks.com/topic/248595-understanding-sessions/page/2/#findComment-1286204 Share on other sites More sharing options...
Drummin Posted November 8, 2011 Share Posted November 8, 2011 Is $_SESSION['carr']; a mis-type? And the extra S? $_SESSION['carr']; $cart = $S_SESSION['cart']; Should be $_SESSION['cart']; $cart = $_SESSION['cart']; And so what I was suggesting was changing this section and adding $_SESSION['cart']=$cart; after making any changes to $cart. if( isset($cart[$id]) ) // If so, add quantity to it. (int) forces $id to be returned as an integer. $cart[$id] += (int) $quantity; $_SESSION['cart']=$cart;// ADDED LINE else // Otherwise, set it to the quantity $cart[$id] = (int) $quantity; $_SESSION['cart']=$cart;// ADDED LINE // Destroy the reference to $cart to avoid acidentally screwing with it elsewhere in the script Quote Link to comment https://forums.phpfreaks.com/topic/248595-understanding-sessions/page/2/#findComment-1286205 Share on other sites More sharing options...
mindapolis Posted November 8, 2011 Author Share Posted November 8, 2011 My only concern is I don't have a variable named id. In my database I have product_title Quote Link to comment https://forums.phpfreaks.com/topic/248595-understanding-sessions/page/2/#findComment-1286209 Share on other sites More sharing options...
Drummin Posted November 8, 2011 Share Posted November 8, 2011 The top section is not right. Should be session_start(); if(isset($_POST['empty']) || !isset($_SESSION['cart'])) $_SESSION['cart'] = array(); //if a cart is clear or doesn't exist yet if(isset($_POST['quantity']) && isset($_POST['product_title'])) { $product_title = $_POST['product_title']; $quantity = $_POST['quantity']; $cart = $_SESSION['cart']; My only concern is I don't have a variable named id. In my database I have product_title Okay, I was going off an earlier post. Not sure if (int) needs to be removed as you're not dealing with an id now. I would take them out and add a check on $_POST['quantity'] if you're concerned about an integer being passed. if( isset($cart[$product_title]) ) // If so, add quantity to it. (int) forces $id to be returned as an integer. $cart[$product_title] += (int) $quantity; $_SESSION['cart']=$cart;// ADDED LINE else // Otherwise, set it to the quantity $cart[$product_title] = (int) $quantity; $_SESSION['cart']=$cart;// ADDED LINE // Destroy the reference to $cart to avoid acidentally screwing with it elsewhere in the script Quote Link to comment https://forums.phpfreaks.com/topic/248595-understanding-sessions/page/2/#findComment-1286211 Share on other sites More sharing options...
mindapolis Posted November 8, 2011 Author Share Posted November 8, 2011 With that code I get this error message. Parse error: syntax error, unexpected T_ELSE Quote Link to comment https://forums.phpfreaks.com/topic/248595-understanding-sessions/page/2/#findComment-1286221 Share on other sites More sharing options...
Drummin Posted November 8, 2011 Share Posted November 8, 2011 OK, with the added lines we need to use brackets. Code not tested. <?php session_start(); if(isset($_POST['empty']) || !isset($_SESSION['cart'])) $_SESSION['cart'] = array(); //if a cart is clear or doesn't exist yet if(isset($_POST['quantity']) && isset($_POST['product_title'])) { $product_title = $_POST['product_title']; $quantity = $_POST['quantity']; $cart = $_SESSION['cart']; if( isset($cart[$product_title]) ){ // If so, add quantity to it. $cart[$product_title] += $quantity; $_SESSION['cart']=$cart;// ADDED LINE } else{ // Otherwise, set it to the quantity $cart[$product_title] = $quantity; $_SESSION['cart']=$cart;// ADDED LINE // Destroy the reference to $cart to avoid acidentally screwing with it elsewhere in the script unset( $cart ); } } require_once("functions.php"); DatabaseConnection(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/248595-understanding-sessions/page/2/#findComment-1286229 Share on other sites More sharing options...
mindapolis Posted November 8, 2011 Author Share Posted November 8, 2011 okay, I dont have any errors, but The quantity still is not transferring to the check out page. Yes, both pages have the same code. Quote Link to comment https://forums.phpfreaks.com/topic/248595-understanding-sessions/page/2/#findComment-1286277 Share on other sites More sharing options...
Drummin Posted November 8, 2011 Share Posted November 8, 2011 IF you add print_r($_SESSION['cart']); to the checkout page, what does it show? Quote Link to comment https://forums.phpfreaks.com/topic/248595-understanding-sessions/page/2/#findComment-1286287 Share on other sites More sharing options...
mindapolis Posted November 8, 2011 Author Share Posted November 8, 2011 This might be hard to explain, but now it 's putting array() under the navbar. I will put the code as well as the links to the pages. http://auntievics.com/test/treatsTest.php http://auntievics.com/test/checkOut.php <?php session_start(); if(isset($_POST['empty']) || !isset($_SESSION['cart'])) $_SESSION['cart'] = array(); //if a cart is clear or doesn't exist yet if(isset($_POST['quantity']) && isset($_POST['product_title'])) { $product_title = $_POST['product_title']; $quantity = $_POST['quantity']; $cart = $_SESSION['cart']; if( isset($cart[$product_title]) ){ // If so, add quantity to it. $cart[$product_title] += $quantity; $_SESSION['cart']=$cart;// ADDED LINE } else{ // Otherwise, set it to the quantity $cart[$product_title] = $quantity; $_SESSION['cart']=$cart;// ADDED LINE // Destroy the reference to $cart to avoid acidentally screwing with it elsewhere in the script unset( $cart ); } } require_once("functions.php"); DatabaseConnection(); ?> ' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>ordering doggy treats</title> <link href="doggyTreats.css" rel="stylesheet" type="text/css" /> <style type="text/css"> #order { margin-right: auto; margin-left: auto; } .orderRow{ padding-bottom: 50px; } h2 { text-align: center; } </style> </head> <body> <?php logo(); navBar(); ?> <form action="" method="post" name="checkOut"> <table id="order"> <tr class="orderRow"> <td> First name:<br /> <input name="fname" type="text" size="10" maxlength="15" /></td> <td>Last name: <br /> <input name="lname" type="text" size="15" maxlength="30" /></td> <td> Address: <br /> <input name="address" type="text" size="30" /></td> </tr> <tr> <tr class = "orderRow"> <td> City: <br /> <input name="city " type="text" size="15" maxlength="20" /> </td> <td> State: <br /> <select name = "state"> <option selected value ="Please choose a state"/> Please choose a state</option> <option value = "AL" />AL</option> <option value = "AK" />AK</option> <option value = "AR" />AR</option> <option value = "AZ" />AZ <option value = "CA" />CA <option value = "CO" />CO <option value = "CT" />CT <option value = "DE" />DE <option value = "DC" />DC <option value = "FL" />FL <option value = "GA" />GA <option value = "HI" />HI <option value = "IA" />IA <option value = "ID" />ID <option value = "IL" />IL <option value = "IN" />IN <option value = "KS" />KS <option value = "KY" />KY <option value = "LA" />LA <option value = "MA" />MA <option value = "ME" />ME <option value = "MD" />MD <option value = "MI" />MI <option value = "MN" />MN <option value = "MO" />MO <option value = "MS" />MS <option value = "MT" />MT <option value = "NC" />NC <option value = "ND" />ND <option value = "NE" />NE <option value = "NH" />NH <option value = "NJ" />NJ <option value = "NM" />NM <option value = "OH" />OH <option value = "OK" />OK <option value = "OR" />OR <option value = "PA" />PA <option value = "RI" />RI <option value = "SC" />SC <option value = "SD" />SD <option value = "TN" />TN <option value = "TX" />TX <option value = "UT" />UT <option value = "VA" />VA <option value = "VT" />VT <option value = "WA" />WA <option value = "WI" />WI <option value = "WV" />WV <option value = "WY" />WY </select> </td> <td> Zip Code:<br /> <input name="zipcode" type="text" size="5" maxlength="5" /> </td> </tr> <tr class = "orderRow"> <td> Phone <br /> Please include area code <br /> <input name="phone" type="text" size="13" maxlength="13" /> </td> <td> Fax:<br /> <input name="" type="text" size="13" maxlength="13" /> </td> <td> Email: <br /> <input name="email " type="text" size="15" maxlength="30" /> </td> </tr> <tr class = "orderRow"> <td> Please choose method of payment: <br /> Check <input name="check " type="radio" value="Check " /> Money Order <input name="money " type="radio" value="Money order " /><br />PayPal<input name="paypal" type="radio" value="Paypal" /> </td> </tr> <tr> <td colspan = "6"> <h2> Pet Information </h2></td> </tr> <tr> <td> Name: <br /> <input name="petName" type="text" size="10" maxlength="20" /> </td> <td> Age: <br /> <select name="age"> <?php for ($age =1; $age <=20; $age ++) { print "<option value=\"age\"> $age</option>"; } ?> </select> </td> <td> Breed:<br /> <select name = "breed"> <option selected value ="Please choose a breed"/> Please choose a breed <option value = "I don't know" />I don't know <option value = "Affernpincher" />Affernpincher <option value = "Afghan Hound" />Afghan Hound <option value = "Airedale Terrier" /> Airedale Terrior <option value = "Akita" /> Akita <option value = "Alaskan Malamute" /> Alaskan Malamute <option value = "Standard American Eskimo Dog"/> Standard American Eskimo Dog <option value = "Miniature American Eskimo Dog"/>Miniature American Eskimo Dog <option value = "Toy American Eskimo Dog"/> Toy American Eskimo Dog <option value = "American Foxhound" /> American Foxhound <option value = "American Staffordshire Terrier" /> American Staffordshhire Terrier <option value = "American Water Spaniel" /> American Water Spaniel <option value = "Australian Shepherd Dog"/> Anatolian Shepherd Dog <option value = "Australian Cattle Dog"/> Australian Cattle Dog <option value = "Australian Shepherd"/> Australian Shepherd <option value = "Australian Terrier" /> Australia Terrier <option value = "Basenji" /> Basenji <option value = "Basset Hound" /> Basset Hound <option value = "Beagle" /> Beagle <option value = "Bearded Collie" /> Bearded Collie <option value = "Beauceron" /> Beauceron <option value = "Bedington Terrier"/> Bedington Terrier <option value = "Belgin Malinois"/> Belgin Malinois <option value = "Belgian Sheepdog"/> Belgian Sheepdog <option value = "Belgian Tervuren"/> Belgian Tervuren <option value = "Bernese Mountain Dog"/> Bernese Mountain Dog <option value = "Bichon Frise"/> Bichon Frise <option value = "Black and Tan Greyhound" /> Black and Tan Greyhound <option value = "Black Russian Terrier" /> Black Russian Terrier <option value = "Bloodhoung" /> Bloodhound <option value = "Border Collie" /> Border Collie <option value = "Border Terrier"/> Border Terrier <option value = "Borzoi"/> Borzoi <option value = "Boston Terrier"/> Boston Terrier <option value = "Bouvier des Flandres"/> Bouvier des Flandres <option value = "Boxer"/> Boxer <option value = "Briard"/> Briard <option value = "Brittany" /> Brittany <option value = "Brussels Griffon" /> Brussels Griffon <option value = "Bulldog" /> Bulldog <option value = "Bullmastiff" /> Bullmasttiff <option value = "Bull Terrier" /> Bull Terrier <option value = "Cairn Terrier" /> Cairn Terrier <option value = "Canaan Dog" /> Canaan Dog <option value = "Cardigan Welsh Corgi" /> Cardigan Welsh Corgi <option value = "Cavalier King Charles Spaniel" />Cavalier King Charles Spaniel <option value = "Chesepeake Bay Retriever" />Chesapeake Bay Retriever <option value = "Chilauhua" /> Chilauhua <option value = "Chinese Created" /> Chinese Crested <option value = "Chinese Shar-Pei" /> Chinese Shar-Pei <option value = "Chow Chow" /> Chow Chow <option value = "Clumber Spaniel" /> Clumber Spaniel <option value = "Cocker Spaniel" /> Cocker Spaniel <option value = "Collie" /> Collie <option value = "Curly-Coated Retrieve" /> Curly-Coated Retriever <option value = "Dachshound" /> Dachshund <option value = "Dalmation" /> Dalmation <option value = "Dandle Dimonnt" /> Dandie Dinmont Terrier <option value = "Doberman Pincher" /> Doberman Pincher <option value = "Dogue de Bordeaux" /> Dogue de Bordeaux <option value = "English Cocker Spaniel" /> English Cocker Spaniel <option value = "English Foxhound" /> English Foxhound <option value = "English Setter" /> English Setter <option value = "English Springer" /> English Springer <option value = "English Toy Spaniel" /> English Toy Spaniel <option value = "Field Spaniel" /> Field Spaniel <option value = "Finnish Spitz" /> Finnish Spitz <option value = "Flat-Coated Retriever" /> Flat-Coated Retriever <option value = "French Bulldog" /> French Bulldog <option value = "German Shepherd Dog" /> German Shepherd Dog <option value = "German Shorthaired Pointer"/>German Shorthaired Pointer <option value = "German Wirehaired Pointer" /> German Wirehaired Pointer <option value = "Giant Schnauzer" /> Giant Schnauzer <option value = "Glen of Imaal Terrier" /> Glen of Imaal Terrier <option value = "Golden Retriever" /> Golden Retriever <option value = "Gorden Setter" /> Gorden Setter <option value = "Great Dane" /> Great Dane <option value = "Greater Swiss Mountain Dog" /> Greater Swiss Mountain Dog <option value = "Great Pyrenees" /> Great Pyrenees <option value = "Greyhound" /> Greyhound <option value = "Harrier" /> Harrier <option value = "Havanese" /> Havanese <option value = "Ibizen Hound" /> Ibizen Hound <option value = "Irish Setter" /> Irish Setter <option value = "Irish Terrier" /> Irish Terrier <option value = "Irish Water Spaniel" /> Irish Water Spaniel <option value = "Irish Wolfhound" /> Irish Wolfhound <option value = "Italian Greyhound" /> Italian Greyhound <option value = "Jack Russell Terrier" /> Jack Russell Terrier <option value = "Japanese Chin" /> Japanese Chin <option value = "Keeshound" /> Keeshound <option value = "Kerry Blue TErrier" /> Kerry Blue Terrier <option value = "Komondor" /> Komondor <option value = "Kuvasz" /> Kuvasz <option value = "Labradar Retriever" /> Labrador Retriever <option value = "Lakeland Terrier" /> Lakeland Terrier <option value = "Lhasa Apso" /> Lhasa Apso <option value = "Lowchen" /> Lowchen <option value = "Maltese" /> Maltese <option value = "Standard Manchester Terrier" /> Standard Manchester Terrier <option value = "Mastiff" /> Mastiff <option value = "Miniature Bull Terrier" /> Miniature Bull Terrier <option value = "Miniature Pinche" /> Miniature Pinscher <option value = "Miniature Poodle" /> Miniature Poodle <option value = "Miniature Schnauzer" />Miniature Schnauzer <option value = "Mutt" />Mutt <option value = "Neopolitan Mastiff" />Neopolitan Mastiff <option value = "Newfoundland " /> Newfoundland <option value = "Newfolk Terrier" />Norfolk Terrier <option value = "Norwegian Elkhound" /> Norwegian Elkhound <option value = "Norwich Terrier" /> Norwich Terrier <option value = "Nova Scotia Duck Tolling Retriever" /> Nova Scotia Duck Tolling Retriever <option value = "Old English Sheepdog" />Old English Sheepdog <option value = "Otterhound" /> Otterhound <option value = "Papillon" />Papillon <option value = "Parson Russell Terrier" /> Parson Russell Terrier <option value = "Pekingese" />Pekingese <option value = "Pembroke Welsh Corgi" />Pembroke Welsh Corgi <option value = "Petit Basset Griffon Vendeen" />Petit Basset Griffon Vendeen <option value = "Pharch Hound" />Pharoh Hound <option value = "Plott" /> Plott <option value = "Pointer" /> Pointer <option value = "Polish Lowland Sheepdog" />Polish Lowland sheepdog <option value = "Pomeranian" /> Pomeranian <option value = "Portuguese Water Dog" />Portuguese Water Dog <option value = "Pug" />Pug <option value = "Pull" />Puli <option value = "Rhodesian Ridgeback" />Rhodesian Ridgeback <option value = "Rottweiler" />Rottweiler <option value = "ASaint Bernard" /> Saint Bernard <option value = "Saluki" /> Saluki <option value = "Samoyed" />Samoyed <option value = "Schipperke" />Schipperke <option value = "Scottish Doverhound" />Scottish Deerhound <option value = "Scottish Terrier" />Scottish Terrier <option value = "Sealyham Terrier" />Sealyham Terrier <option value = "Shetland Sheepdog" />Shetland Sheepdog <option value = "Shiba Inu" />Shiba Inu <option value = "Shih Tzu" />Shih Tzu <option value = "Siberian Husky" />Siberian Husky <option value = "Silky Terrier" />Silky Terrier <option value = "Skye Terrier" />Skye Terrier <option value = "Smooth Fox Terrier" />Smooth Fox Terrier <option value = "Soft Coated Wheaten Terrier" />Soft Coated wheaten Terrier <option value = "Spinone Italiano" />Spinone Italiano <option value = "Staffordshire Bull Terrier" />Staffordshire Bull Terrier <option value = "Standard Poodle" />Standard Poodle <option value = "Standard Schnauer" /> Standard Schnauzer <option value = "Suseex Spaniel" />Sussex Spaniel <option value = "Swedish Vallhound" />Swedish Vallhund <option value = "Tibertan Mastiff" />Tibetan Mastiff <option value = "Tibertan Spaniel" />Tibetan Spaniel <option value = "Tibetan Terrier" />Tibetan Terrier <option value = "Toy Fox Terrier" />Toy Fox Terrier <option value = "Toy Manchester Terrier" />Toy Manchester Terrier <option value = "Toy Poodle" />Toy Poodle <option value = "Vizela" />Vizela <option value = "Weimaraner" />Weimaraner <option value = "Welsh Springer Spaniel" />Welsh Springer Spaniel <option value = "Welsh Terrier" />Welsh Terrier <option value = "West Highland White Terrier" />West Highland White Terrier <option value = "Whippet" />Whippet <option value = "Wire Fox Terrier" />Wire Fox Terrier <option value = "Wirehaired Pointing Griffon" />Wirehaired Pointing Griffon <option value = "Yorkshire Terrier" />Yorkshire Terrier </select> </td> </tr> <tr> <td>Nutritional Needs:</td> <td><textarea name="nutritionalNeeds" cols="17" rows="5"></textarea> </td> </tr> <tr> <td>Special Instructions</td> <td><textarea name="specialInstructions" cols="17" rows="5"></textarea></td> </tr> <tr> <td colspan = "6"><h2>Order Information</h2></td> </tr> <tr> <ul> <?php foreach($_SESSION['cart'] as $product_title => $quantity) { echo "<li>$product_title $quantity</li>"; } print_r($_SESSION['cart']); ?> </ul> </tr> <tr> <td> <input name="Submit" type="submit" value="Order Treats!" /></td><td><input name="reset" type="submit" value="Cancel Order" /> </td> </tr> </table> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/248595-understanding-sessions/page/2/#findComment-1286312 Share on other sites More sharing options...
Drummin Posted November 8, 2011 Share Posted November 8, 2011 You've got a lot of html issues to address but to start, move this php code out of your table <tr> elements and put the list (<ul> etc) after your table. The array() is shown there because print_r() is between <tr></tr> tags along with your list. Let me know what print_r shows after adding an item to the cart. <tr> <ul> <?php foreach($_SESSION['cart'] as $product_title => $quantity) { echo "<li>$product_title $quantity</li>"; } print_r($_SESSION['cart']); ?> </ul> </tr> Quote Link to comment https://forums.phpfreaks.com/topic/248595-understanding-sessions/page/2/#findComment-1286352 Share on other sites More sharing options...
mindapolis Posted November 9, 2011 Author Share Posted November 9, 2011 I'm not sure I'm following you but I put that php code below the table tag and it put array() under the navbar. <tr> <td colspan = "6"><h2>Order Information</h2></td> </tr> <tr> </tr> <tr> <td> <input name="Submit" type="submit" value="Order Treats!" /></td><td><input name="reset" type="submit" value="Cancel Order" /> </td> </tr> </table> <ul> <?php foreach($_SESSION['cart'] as $product_title => $quantity) { echo "<li>$product_title $quantity</li>"; } print_r($_SESSION['cart']); ?> </ul> </form> Quote Link to comment https://forums.phpfreaks.com/topic/248595-understanding-sessions/page/2/#findComment-1286704 Share on other sites More sharing options...
Drummin Posted November 9, 2011 Share Posted November 9, 2011 The point is after submitting your form does array() then hold the values you expect. This is why I've asked what does print_r show after submitting the form. Is it still array() or is it something like array(product_name => 2). Quote Link to comment https://forums.phpfreaks.com/topic/248595-understanding-sessions/page/2/#findComment-1286728 Share on other sites More sharing options...
xyph Posted November 9, 2011 Share Posted November 9, 2011 print_r is a debugging feature. It outputs the structure of an array to verify it contains what you want it to. Generally, it's hard to read when displayed in a browser. You need to either view-source or surround it in <pre> tags to see the formatting. When you print_r() an empty array, it will simply output Array ( ) This will appear as Array ( ) if you don't surround it in pre tags, or aren't viewing the source of the page. Quote Link to comment https://forums.phpfreaks.com/topic/248595-understanding-sessions/page/2/#findComment-1286742 Share on other sites More sharing options...
mindapolis Posted November 9, 2011 Author Share Posted November 9, 2011 It 's just putting array(). Quote Link to comment https://forums.phpfreaks.com/topic/248595-understanding-sessions/page/2/#findComment-1286760 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.