Solved

problem with if statements

Posted on 2007-11-15
9
219 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

943 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

7 Experts available now in Live!

Get 1:1 Help Now