troubleshooting Question

Why is my foreach loop not returning values from $_SESSION variable

Avatar of peter-cooper
peter-cooper asked on
PHP
8 Comments1 Solution581 ViewsLast Modified:
Hi
I have set a $_SESSION variable and cannot see why my foreach loop is not working. All get if I echo the var $v all I get is white screen. If I echo my session var then I can see the data that is being passed is in the format wd10,wd11,wd12.  I would be grateful if someone could check my loop and point out my mistake. Thanks

session var

$_SESSION['boxdest2']

Loop

<?php

foreach ($_SESSION['boxdest2'] as $key=>$value)
	{	
  $temp = explode(",", $value);
  foreach($temp as $k => $v )
  {
    $query = "SELECT * FROM boxes WHERE customer = '$_SESSION[kt_idcode_usr]' AND status = 1 AND custref = '$v'";
    $result = mysql_query($query) or die(mysql_error());
    $row = mysql_fetch_array($result) or die(mysql_error());
    $rack = $row['rack'] . "-" . $row['column'] . "-" . $row['row'] .  "-" . "(" . $row['bay'] . ")";
		
//    $query = "UPDATE boxes SET status = '9' WHERE customer = '$customer' AND department = '$dept' AND custref = '$v'";
//    mysql_query($query) or die('Error, query failed');
//	
	$query = 'INSERT INTO `act` (`slot`, `service`, `activity`, `department`, `company`, `address`, `user`, `item`, `destroyedby`, `destroyedby_date`, `date`, `new`) VALUES (\''.$rack.'\', \''.$service.'\', \''.$activitys.'\', \''.$dept.'\', \''.$company.'\', \''.$address.'\', \''.$user.'\', \''.$v.'\', \''.$user.'\',NOW(),NOW(), \''.$new.'\');';
   mysql_query($query) or die('Error, query failed');
	}
	}
?>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros