Solved

problem with if statements

Posted on 2007-11-15
9
221 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Wordpress Pagination Function Not working ? 7 39
PHP Installer 5 38
How do I fix this UPDATE error? 7 32
What is this? I've never seen this... 2 9
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to count occurrences of each item in an array.
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.

830 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