Jump to content

Recommended Posts

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;
}
}

Link to comment
https://forums.phpfreaks.com/topic/190474-form-checkbox-values-in-php/
Share on other sites

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;
   }
}

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.