SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Evangelist CyberFuture's Avatar
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Strange IF statement problem

    Something is not working right here.
    PHP Code:
    echo "TESTER = $tester <br>";
        if (
    $tester == "mod")
         {
         echo 
    "SECOND TEST :: TESTER = $tester <br>";

    The output is:

    TESTER = 1
    SECOND TEST :: TESTER = 1

    As the output clearly doesn't equal "mod", so why is the secont test being echoed????!!!

    Any ideas?

    Thanks

  2. #2
    SitePoint Addict Huscy's Avatar
    Join Date
    Jul 2002
    Location
    Newcastle, UK
    Posts
    318
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    strange one indeed, try doing
    PHP Code:
    if ($tester == "mod" )
    {
    echo 
    "$tester";

    else
    {
    echo 
    "$tester";

    just out of curiosity

    before i post, is "mod" not some PHP reserved word?
    (not sure, would be in pascal, just a thought)

  3. #3
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mod is in a string, so it doesn't matter anyways. (But no I don't think it is reserved.)

    anyways, when you are echoing a variable, lose the double quotes.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  4. #4
    SitePoint Evangelist CyberFuture's Avatar
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I changed "mod" to "modd" and here's the new code:
    PHP Code:
    echo "TESTER = $tester <br>";
    if (
    $tester == "modd")
         {
         echo 
    "SECOND TEST :: TESTER = $tester <br>";
          }
    else
         { 
         echo 
    "THIRD TEST :: TESTER = $tester <br>"
         } 
    The output is:
    TESTER = 1
    SECOND TEST :: TESTER = 1

    I'm scratching my head on this one

  5. #5
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try
    PHP Code:
    if ($tester==='modd'
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  6. #6
    SitePoint Evangelist CyberFuture's Avatar
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cyborg from dh
    when you are echoing a variable, lose the double quotes.
    Why?? I was taught NEVER use single quotes on variables, because PHP treats variables in single quotes as literals. But not with double quotes.

  7. #7
    SitePoint Evangelist CyberFuture's Avatar
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks cyborg that did the trick.

  8. #8
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by CyberFuture
    Why?? I was taught NEVER use single quotes on variables, because PHP treats variables in single quotes as literals. But not with double quotes.
    He was referring to
    Quote Originally Posted by Huscy
    PHP Code:
    echo "$tester"
    where there is no need for any kind of quotes.
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  9. #9
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    echo $tester
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •