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!

trouble controlling session var

Status
Not open for further replies.

krisc13

Programmer
Jul 17, 2006
42
US
I am new to php so forgive my greenness. I've also looked in the online php manual for basics on session variables. I am simply trying to set a variable called "newcust" to either tru or false. The page only recognizes this variable as true no matter where or when I change it. I am changing it after session.start() as I've seen in the manual. What I have is simply:

Code:
case 'edit_cust':
   $_SESSION["newcust"]=FALSE;
   if ($sxr->can_edit(2)) {
    $popup_file = INCLUDE_DIR.'/popups/agent/customer_details.php';
    }

Then on my page:

Code:
<?
  if ($_SESSION["newcust']=FALSE){
?>
<a class="item" onclick="saveEdit();" href="#">
<img src="<? echo $img_dir; ?>/small_icons/save.gif" />Save & Close</a>
<?
   }
?>

and yet it returns TRUE. I'm sure I'm missing something simple. I'd appreciate any suggestions. Thanks!
 
The error lies in the fact that a single equal sign performs an assignment:
Code:
<?
  if ($_SESSION['newcust']=FALSE){
?>
So, in fact, you are assigning the value FALSE to the session variable. You need two equal signs to perform a comparison:
Code:
<?
  if ($_SESSION['newcust']==FALSE){
?>

The assignment will always return true, as the value was successfully assigned. Also, pay attention to the double/single quotes in your posted code.
 
How silly. That worked thank you so much. I should know better can't believe it was that simple. Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top