Solved

problem with if statements

Posted on 2007-11-15
9
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

696 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