mikebarbaro Posted January 31, 2010 Share Posted January 31, 2010 Hello, I have the following code displaying a checkbox with some other options as seen on www.tandoorpgh.com/placeanorder under the section Main Courses (non-vegetarian). //Main Courses (non-vegetarian) echo '<h3>Main Courses (non-vegetarian)</h3>'; $query = mysql_query("SELECT * FROM `menu` WHERE category = 'entree'"); while($row = mysql_fetch_array($query)) { echo '<input type="checkbox" name="title[]" value="' . $row['title'] . '" /><b><span id=text_black>' . $row['title'] . '</span> - Quantity: <input type=text name=quantity maxlength=1 size=1> - Spice Level: <select name=spice_level> <option value=Mild>Mild</option> <option value=Medium>Medium</option> <option value=Hot>Hot</option> <option value=Extra Hot>Extra Hot</option> </select></b> <span id="text_black">- $' . $row['price'] . '<br><i>' . $row['description'] . '</i></span> <br><br>'; } The problem I'm having is when the form process script runs, as seen below, the script only picks up the checkbox values which is the entrees' name but I need it to attach the quantity and spice level to each item selected as well. Can anyone help? It's appreciated! $item=$_POST['title']; $_SESSION['items'] = $item; foreach ($item as $itemname) { $query = mysql_query("SELECT * FROM `menu` WHERE title = '$itemname'"); while($row = mysql_fetch_array($query)) { $total = $total + $row['price']; $_SESSION['quantity'] = $_POST['quantity']; echo "<p>" . $_SESSION['quantity'] . " " . $row['title'] . " - <span style=color:#000;>$" . $row['price'] . "</span></p>"; $_SESSION['total'] = $total; } } Quote Link to comment https://forums.phpfreaks.com/topic/190474-form-checkbox-values-in-php/ Share on other sites More sharing options...
wildteen88 Posted January 31, 2010 Share Posted January 31, 2010 Change your form code to //Main Courses (non-vegetarian) echo '<h3>Main Courses (non-vegetarian)</h3>'; $query = mysql_query("SELECT * FROM `menu` WHERE category = 'entree'"); $i = 0; while($row = mysql_fetch_array($query)) { echo '<input type="checkbox" name="title[$i]" value="' . $row['title'] . '" /><b><span id=text_black>' . $row['title'] . '</span> - Quantity: <input type=text name="quantity[$i]" maxlength=1 size=1> - Spice Level: <select name="spice_level[$i]"> <option value=Mild>Mild</option> <option value=Medium>Medium</option> <option value=Hot>Hot</option> <option value=Extra Hot>Extra Hot</option> </select></b> <span id="text_black">- $' . $row['price'] . '<br><i>' . $row['description'] . '</i></span> <br><br>'; $i++; } When you process the form use $item=$_POST['title']; $_SESSION['items'] = $item; foreach ($item as $itemkey => $itemname) { $query = mysql_query("SELECT * FROM `menu` WHERE title = '$itemname'"); while($row = mysql_fetch_array($query)) { $total = $total + $row['price']; $_SESSION['quantity'] = $_POST['quantity'][$itemkey]; echo "<p>" . $_SESSION['quantity'] . " " . $row['title'] . " - <span style=color:#000;>$" . $row['price'] . "</span></p>"; $_SESSION['total'] = $total; } } Quote Link to comment https://forums.phpfreaks.com/topic/190474-form-checkbox-values-in-php/#findComment-1004717 Share on other sites More sharing options...
mikebarbaro Posted January 31, 2010 Author Share Posted January 31, 2010 hmm it doesn't seem like that worked. It still only displays the selected titles... Quote Link to comment https://forums.phpfreaks.com/topic/190474-form-checkbox-values-in-php/#findComment-1004734 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.