Solved

problem with if statements

Posted on 2007-11-15
9
218 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now