Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What have I missed?

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
Piece of code that checks if session variable contains value >0.

$returns = FALSE;
for ($i=1;$i<40;$i++)
if ($_SESSION['QTY'][$i]>0) {
$returns = TRUE;
}
if($returns != TRUE) { header('Location:index.php');
}

//otherwise carry on down page of code

The above code gets ignored either way of the result being true or false. Wondering if there is an else bit left out. Thanks
 
personal preferance I guess for me... try
if(!$returns)

Also I don't see what exactly your for loop is encapsulating {}
 
are there 40 members of your array $_SESSION['QTY']? and are you certain that there is nothing stored in the zero element?

i would tend to use the following alternative:

Code:
$returns = false;
foreach ($_SESSION['QTY'] as $key=>$val) {
 if ($val > 0) {
  $returns = true;
  $var = $key; 
  break;
 }
}
//for debug
 echo "the first non-zero value was at element $var";
 echo "<pre>" . print_r($_SESSION,true) . "</pre>";
 if ($returns !== true) {
  echo "here we would redirect";
  die();
 }
//end debug code
 if ($returns !== true) {
  session_write_close();
  header("Location:index.php");
 }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top