Solved

problem with if statements

Posted on 2007-11-15
9
220 Views
Last Modified: 2010-05-18
in php., whats the difference between the 2 lines?

if ($HTTP_SESSION_VARS["section"] == "credit")

if ($HTTP_SESSION_VARS["section"] = "credit")
0
Comment
Question by:markmchugh
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 9

Accepted Solution

by:
waygood earned 500 total points
ID: 20290421
the first one compares the values
the second checks the result of setting the value to "credit"

I suggest you use $_SESSION['section'] instead of $HTTP_SESSION_VARS['section']
0
 
LVL 48

Expert Comment

by:hernst42
ID: 20290528
$HTTP_SESSION_VARS["section"] = "credit" is an assignment. You overwrite or set the content of variable $HTTP_SESSION_VARS["section"]  to credit. If youse in an if-statements it's typical a typo/bug

$HTTP_SESSION_VARS["section"] == "credit" is a comaprison if variable $HTTP_SESSION_VARS["section"] contains the value "credit"

0
 

Author Comment

by:markmchugh
ID: 20290941
this seems to break my code?

      if ($_SESSION["section"] == "credit") {
      $_SESSION["var1"] = $frmloanamt;
      $_SESSION["var2"] = $loanterms;
      )
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 48

Expert Comment

by:hernst42
ID: 20291021
what do you mean by breaking your code ?

Also to note that $HTTP_SESSION_VARS["section"] = "credit" is allways true when used in side if, as "credit" is a true value in php.
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20291107
by break your code do you mean it doesn't execute the statements in the if statement? This is probably because $_SESSION["section"] == "credit" evaluates to false, try and echo out $_SESSION["section"] and see what value it contains.
0
 

Author Comment

by:markmchugh
ID: 20291346
do i use $_SESSION["section"]  

or

$_SESSION['section']

to assign something?
0
 
LVL 82

Expert Comment

by:hielo
ID: 20291723
The problem with:
 if ($_SESSION["section"] == "credit") {
      $_SESSION["var1"] = $frmloanamt;
      $_SESSION["var2"] = $loanterms;
      )
is that you have a closing parenthesis instead of brace }
Try:

session_start();
$_SESSION['section'] = 'credit';

 if ($_SESSION["section"] == "credit") {
      $_SESSION["var1"] = $frmloanamt;
      $_SESSION["var2"] = $loanterms;
}

On another note:
if ($HTTP_SESSION_VARS["section"] == "credit")
means: "is $HTTP_SESSION_VARS["section"]  equal to 'credit'?"
However:
if ($HTTP_SESSION_VARS["section"] = "credit")

is equivalent to the following two statements:
$HTTP_SESSION_VARS["section"] = "credit";
if( $HTTP_SESSION_VARS["section"] )
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20291736
@markmchugh:

they are the same thing, and both will work :)
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20291741
@hielo

Good spotting!
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Move wordpress site 3 40
PHP: Insert Data into MySQL 5 40
PHP populating an array. 4 25
google map tracking website 5 24
This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question