why doesn't this work? - using && with an IF statement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • NotGiven

    why doesn't this work? - using && with an IF statement

    session_start() ;
    if (isset($HTTP_SE SSION_VARS[un']))&&($HTTP_SESS ION_VARS['un'] != '')
    echo "hello";

    It doesn't throw an error it just doesn't display anything

    However, this works:

    session_start() ;
    if (isset($HTTP_SE SSION_VARS[un']))
    echo "hello";

    Thanks.


  • Pedro Graca

    #2
    Re: why doesn't this work? - using && with an IF statement

    NotGiven wrote:[color=blue]
    > session_start() ;
    > if (isset($HTTP_SE SSION_VARS[un']))&&($HTTP_SESS ION_VARS['un'] != '') echo "hello";[/color]
    (-----(============== =========))
    The &&'s are outside the if () !!!
    [color=blue]
    > It doesn't throw an error it just doesn't display anything[/color]

    I think you should have received a "parse error"
    [color=blue]
    > However, this works:[/color]

    PHP can be nice sometimes, can't it? :)
    [color=blue]
    > session_start() ;
    > if (isset($HTTP_SE SSION_VARS[un']))[/color]
    _______________ _______________ ^^^^^
    I assume this is a typing mistake
    [color=blue]
    > echo "hello";[/color]


    --
    USENET would be a better place if everybody read: | to email me: use |
    http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
    http://www.netmeister.org/news/learn2quote2.html | header, textonly |
    http://www.expita.com/nomime.html | no attachments. |

    Comment

    • Gary L. Burnore

      #3
      Re: why doesn't this work? - using && with an IF statement

      On Thu, 8 Jul 2004 20:39:39 -0400, "NotGiven" <noname@nonegiv en.net>
      wrote:
      [color=blue]
      >session_start( );
      >if (isset($HTTP_SE SSION_VARS[un']))&&($HTTP_SESS ION_VARS['un'] != '')[/color]

      Could it be that you missed the single quote before un' that you
      missed here?



      [color=blue]
      >echo "hello";
      >
      >It doesn't throw an error it just doesn't display anything
      >
      >However, this works:
      >
      >session_start( );
      >if (isset($HTTP_SE SSION_VARS[un']))
      >echo "hello";
      >
      >Thanks.
      >[/color]

      --
      gburnore@databa six dot com
      ---------------------------------------------------------------------------
      How you look depends on where you go.
      ---------------------------------------------------------------------------
      Gary L. Burnore | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
      | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
      DataBasix | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
      | ÝÛ³ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ÝÛ³
      Black Helicopter Repair Svcs Division | Official Proof of Purchase
      =============== =============== =============== =============== ===============
      Want one? GET one! http://signup.databasix.com
      =============== =============== =============== =============== ===============

      Comment

      • Zurab Davitiani

        #4
        Re: why doesn't this work? - using &amp;&amp; with an IF statement

        NotGiven wrote:
        [color=blue]
        > if (isset($HTTP_SE SSION_VARS[un']))&&($HTTP_SESS ION_VARS['un'] != '')[/color]

        Watch your parentheses and a missing single quote.

        On a side note, unless you are writing this for older versions of PHP, you
        should use $_SESSION array instead.

        Comment

        • Michael Austin

          #5
          Re: why doesn't this work? - using &amp;&amp; with an IF statement

          NotGiven wrote:
          [color=blue]
          > session_start() ;
          > if (isset($HTTP_SE SSION_VARS[un']))&&($HTTP_SESS ION_VARS['un'] != '')
          > echo "hello";
          >
          > It doesn't throw an error it just doesn't display anything
          >
          > However, this works:
          >
          > session_start() ;
          > if (isset($HTTP_SE SSION_VARS[un']))
          > echo "hello";[/color]

          because the echo statment is not a part of the if statement. you need

          if (isset($HTTP_SE SSION_VARS['un'])) {
          echo "hello";
          }[color=blue]
          >
          > Thanks.
          >
          >[/color]
          you're welcome...

          Michael Austin.

          Comment

          • Alvaro G Vicario

            #6
            Re: why doesn't this work? - using &amp;&amp; with an IF statement

            *** NotGiven wrote/escribió (Thu, 8 Jul 2004 20:39:39 -0400):[color=blue]
            > However, this works:
            >
            > session_start() ;
            > if (isset($HTTP_SE SSION_VARS[un']))
            > echo "hello";[/color]

            It doesn't:

            Parse error: parse error, expecting `']''



            --
            --
            -- Álvaro G. Vicario - Burgos, Spain
            --

            Comment

            • michel

              #7
              Re: why doesn't this work? - using &amp;&amp; with an IF statement


              "Michael Austin" <maustin@firstd basource.com> wrote in message
              news:V2nHc.7296 $p%6.6360@newss vr23.news.prodi gy.com...[color=blue]
              > NotGiven wrote:
              >[color=green]
              > > session_start() ;
              > > if (isset($HTTP_SE SSION_VARS[un']))&&($HTTP_SESS ION_VARS['un'] != '')
              > > echo "hello";
              > >
              > > It doesn't throw an error it just doesn't display anything
              > >
              > > However, this works:
              > >
              > > session_start() ;
              > > if (isset($HTTP_SE SSION_VARS[un']))
              > > echo "hello";[/color]
              >
              > because the echo statment is not a part of the if statement. you need
              >
              > if (isset($HTTP_SE SSION_VARS['un'])) {
              > echo "hello";
              > }[color=green]
              > >[/color][/color]
              That's not true. You only need these parenthesis when wanting to execute
              more than one line.
              in this case, where only the echo is done, he don't need those


              Comment

              Working...