SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Resident Boozehound simontheak's Avatar
    Join Date
    Jun 2003
    Location
    _root.europe.uk.london
    Posts
    965
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A seriously frustrating (noobie?) PHP problem

    Ok, I've been looking at this for about an hour now and can find no rhyme or reason why this isn't working.

    I'm from the UK, and am trying to implement a bit of Geo Targetting into my website. I've created a function that queries a database fine, so that when I output $country from my laptop, the string "GB" is printed on the screen.

    Great.

    Now for some reason, when I put in the following code, the string value changes to "US" despite the fact that I'm still accessing exactly the same page from exactly the same location:

    PHP Code:
    <? if($country="US"
        {
        echo(
    '<link rel="stylesheet" href="../style/us.css" type="text/css" media="screen" />');
        }
        else {
        echo(
    '<link rel="stylesheet" href="../style/default.css" type="text/css" media="screen" />');
        }
        
    ?>
    When that simple if() statement is put on to the page, the string GB disappears and the string "US" appears in its place.

    I just don't understand it! How can that be possible from a simple if() statement? No where am I changing the value of the $country variable, so why should it change when I input a simple piece of code??

    Any help would be seriously appreciated.

    Thanks very much.

  2. #2
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try two equal signs in the if statement, you are using an assignment operator and saying:
    if (set country to US (returns true I think)), so it processes the first set..

    Do this:
    if($country== "US")

  3. #3
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,070
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Off Topic:


    Quote Originally Posted by JREAM View Post
    if (set country to US (returns true I think))
    Nope, returns "US"

    Try
    PHP Code:
    var_dump($country="US"); 

    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


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
  •