Jump to content

Session variable Problem!


mikebarbaro

Recommended Posts

Hello,

 

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!

Link to comment
https://forums.phpfreaks.com/topic/190682-session-variable-problem/
Share on other sites

$_SESSION['qty']=$items

 

 

HTH

Teamatomic

 

Now it just displays each qty and spice_level as the word Array??

 

First script:

 

$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']=$items; 
	$_SESSION['spice_level']=$items;





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

 

Faxing script:

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.