SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2012
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    GET is working weird?

    Hey guys! I have a page that displays different things when you click on different links, but it's all done on one page. here's the code scheme i have:
    PHP Code:
    <?php
    if(!isset($_GET['page'])){  ?>
    <div id="container">
        <nav>
            <ul>
                <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?page=make_post">Make a Post</a></li>
                <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?page=view_posts">View Posts</a></li>
                <li><a href="home.php">Go to Feed</a></li>
            </ul>
        </nav>
    </div>
        <?php }elseif(isset($_GET['page']) == 'make_post'){?>
    <div id="post-form">
        post form test
    </div>
        <?php  }elseif(isset($_GET['page']) == 'view_posts'){ ?>
    <div id="view-posts">
        view post test
    </div>
        <?php ?>
    it was working yesterday, but while editing i must have changed something to make it not work but when you click the 'view posts' link, it displays the 'make a post' page. but when you click the make a post link, it displays the right content. i can't figure out why the view posts link doesn't work..help??

  2. #2
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    I'm certainly not an expert in this area but it seems like this is a bit off:
    PHP Code:
    <?php }elseif(isset($_GET['page']) == 'make_post'){?>
    Using isset() will return a boolean value but yet you're checking that boolean value against a string, 'make_post'. I would remove the isset() as it's unnecessary here.
    PHP Code:
    <?php }elseif($_GET['page'] == 'make_post'){?>
    Do the same for the other elseif statement.
    TAKE A WALK OUTSIDE YOUR MIND.

  3. #3
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    Jeff's pretty much got it on the head.

    more likely, caleb, you meant to do a combination and just forgot the middle part;
    if(isset($_GET['page']) && $_GET['page'] == 'make_post')
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2012
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OH! stupid mistake =P thanks guys!

  5. #5
    SitePoint Addict kduv's Avatar
    Join Date
    May 2012
    Location
    Maui, HI
    Posts
    211
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    You really don't need to use isset() for the second two if statements as the first one already checks to see it it's set.

  6. #6
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    A fair point. Given that the first if checks for the inverse-isset, all ElseIf's attached to it are guaranteed to have passed this check. Good catch.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  7. #7
    SitePoint Addict kduv's Avatar
    Join Date
    May 2012
    Location
    Maui, HI
    Posts
    211
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    .-)


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
  •