I have the following code processing a form located at tandoorpgh.com/placeanorder which declares two variables, $qty and $spice_level from the array. I try saving them as Session variables and then passing them onto the following script but nothing prints out.
They echo here perfectly:
$items = $_POST['items'];
foreach($items as $item){
$qty = $_POST['qty_' . $item]; // now the quantity of that particular item will be stored here
$spice_level = $_POST['spice_level_' . $item]; // now the spice_level of that particular item will be stored here
$_SESSION['qty'] = $_POST['qty_' . $item];
$_SESSION['spice_level'] = $_POST['spice_level_' . $item];
$query = mysql_query("SELECT * FROM `menu` WHERE id = '$item'");
while($row = mysql_fetch_array($query)) {
if ($qty > 0) {
$total = $total + $row['price'] * $qty;
echo "<p>$qty - " . $row['title'] . " - <span style=color:#000;>$" . $row['price'] . "</span> - Spice Level: $spice_level</p>";
} else {
$total = $total + $row['price'];
echo "<p>1 - " . $row['title'] . " - <span style=color:#000;>$" . $row['price'] . "</span> - Spice Level: $spice_level</p>";
}
But when called up on the following script here within $finalitems, they display as blank. This script here is for faxing the variables:
$items = $_SESSION['items'];
foreach ($items as $item) {
$spice_level = $_SESSION['spice_level'];
$qty = $_SESSION['quantity'];
$sql = mysql_query("SELECT * FROM `menu` WHERE id = '$item'");
while($row = mysql_fetch_array($sql)){
$finalitems .= $qty . ' - ' . $row['title'] . ' - Spice Level: ' . $spice_level . '<br><br />'; //changed this line
}}
Any help is highly appreciated. I’ve been working on this for days. Thanks!
Maybe I’m going blind, but you also don’t define the $_SESSION[‘items’] anywhere.
So if that one is empty, no loop will be executed in the second page.
Here’s more of a complete script and yes I do have session_start() at the beginning. This is the first script that processes the form and displays the info for the customer to review.
$pickup_delivery = $_POST['pickup_delivery'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$city = $_POST['city'];
$zip = $_POST['zip'];
$notes = $_POST['notes'];
$items = $_POST['items'];
$_SESSION['pickup_delivery'] = $pickup_delivery;
$_SESSION['first_name'] = $first_name;
$_SESSION['last_name'] = $last_name;
$_SESSION['email'] = $email;
$_SESSION['phone'] = $phone;
$_SESSION['address'] = $address;
$_SESSION['city'] = $city;
$_SESSION['zip'] = $zip;
$_SESSION['notes'] = $notes;
$_SESSION['items'] = $items;
echo "<span id=text_black>Order is for $pickup_delivery</span><br><br>$first_name $last_name<br>$email<br>$phone<br>$address<br>$city, PA $zip<br><br><span id=text_black>Order Notes:</span><br>$notes";
?>
<h3>Items Ordered</h3>
<?php
$items = $_POST['items'];
foreach($items as $item){
$qty = $_POST['qty_' . $item]; // now the quantity of that particular item will be stored here
$spice_level = $_POST['spice_level_' . $item]; // now the spice_level of that particular item will be stored here
$_SESSION['qty'] = $_POST['qty_' . $item];
$_SESSION['spice_level'] = $_POST['spice_level_' . $item];
$query = mysql_query("SELECT * FROM `menu` WHERE id = '$item'");
while($row = mysql_fetch_array($query)) {
if ($qty > 0) {
$total = $total + $row['price'] * $qty;
echo "<p>$qty - " . $row['title'] . " - <span style=color:#000;>$" . $row['price'] . "</span> - Spice Level: $spice_level</p>";
} else {
$total = $total + $row['price'];
echo "<p>1 - " . $row['title'] . " - <span style=color:#000;>$" . $row['price'] . "</span> - Spice Level: $spice_level</p>";
}
$_SESSION['total'] = $total;
}
}
Then here is the script that actually faxes the information. This is the one where right now quantity and spice_level just display the word Array.
$items = $_SESSION['items'];
foreach ($items as $item) {
$spice_level = $_SESSION['spice_level'];
$qty = $_SESSION['qty'];
$sql = mysql_query("SELECT * FROM `menu` WHERE id = '$item'");
while($row = mysql_fetch_array($sql)){
$finalitems .= $qty . ' - ' . $row['title'] . ' - Spice Level: ' . $spice_level . '<br><br />'; //changed this line
}}