mikebarbaro Posted January 25, 2010 Share Posted January 25, 2010 Hello, I am designing an online ordering system for a restaurant. I have a menu with check boxes by each item where the customer can select which items they desire. The menu is located at tandoorpgh.com/placeanorder The problem is that when the order is processed I need it to store each checked off item as a session variable. In the following code, it only selects the first item checked and not the rest if there is more than one. Any help is appreciated! $item=$_POST['title']; foreach ($item as $itemname) { $query = mysql_query("SELECT * FROM `menu` WHERE title = '$itemname'"); while($row = mysql_fetch_array($query)) { $total = $total + $row['price']; echo "<p>" . $row['title'] . " - <span style=color:#000;>$" . $row['price'] . "</span></p>"; $allitems = $row['title'] . $row['price']; $_SESSION['items'] = $allitems; $_SESSION['total'] = $total; } } Quote Link to comment Share on other sites More sharing options...
schilly Posted January 25, 2010 Share Posted January 25, 2010 As far as I can tell you are only looping through one item. Are you wanting to loop through your whole POST array? Quote Link to comment Share on other sites More sharing options...
mikebarbaro Posted January 25, 2010 Author Share Posted January 25, 2010 Well, my biggest confusion is the following code snippet containing the echo displays all items that were checked off from the form, yet when I try and save them as a session variable it only displays one item. echo "<p>" . $row['title'] . " - <span style=color:#000;>$" . $row['price'] . "</span></p>"; Say three items from the menu at tandoorpgh.com/placeanorder are checked off. When they come to this page to review their order the echo statement displays all three, but I cannot figure out why they won't save as a session variable? I've tried $_SESSION['items'] = $row['title']; within the loop statement but no luck... Do I maybe need to loop through the whole array? Any help is very much appreciated! Quote Link to comment Share on other sites More sharing options...
schilly Posted January 25, 2010 Share Posted January 25, 2010 oh i see. well each time you loop through that while you are overwriting the session var from the previous loop. so you might want to do something like: $_SESSION['items'][] = $allitems; $_SESSION['total'] += $total; that will add up the total and create an array of items. Quote Link to comment Share on other sites More sharing options...
mikebarbaro Posted January 26, 2010 Author Share Posted January 26, 2010 It just doubled the total and still displays as Array Quote Link to comment Share on other sites More sharing options...
schilly Posted January 26, 2010 Share Posted January 26, 2010 ok can you post the output of this <?PHP echo "<pre>" . print_r($_POST,true) . "</pre>"; $item=$_POST['title']; foreach ($item as $itemname) { $query = mysql_query("SELECT * FROM `menu` WHERE title = '$itemname'"); while($row = mysql_fetch_array($query)) { $total = $total + $row['price']; echo "<p>" . $row['title'] . " - <span style=color:#000;>$" . $row['price'] . "</span></p>"; $allitems = $row['title'] . $row['price']; $_SESSION['items'][] = $allitems; $_SESSION['total'] += $total; } } echo "<pre>" . print_r($_SESSION,true) . "</pre>"; ?> Quote Link to comment Share on other sites More sharing options...
mikebarbaro Posted January 26, 2010 Author Share Posted January 26, 2010 thanks im going to try it out! Quote Link to comment 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.