jquery - Isset get page with php correct usage

632

I'm calling my pages on 'index.php' via 'incude' statements. I've had to use 'isset' to get them to work but the 'yourtweets.php' does not load when I click the link in my navbar. Am I using it correctly?

Link code;

 <a href="?page=yourtweets" class="nav-link">Your Tweets</a>

index.php code;

<?php
      include("functions.php");
      include("views/header.php");

      if (isset($_GET['page']) == 'timeline') {
          include("views/timeline.php");

        } else if (isset($_GET['page']) == 'yourtweets') {

            include("views/yourtweets.php");

      } else {
        include("views/home.php");
      }
    ?>
49

Answer

Solution:

From the PHP Manual:

Returns TRUE if var exists and has value other than NULL. FALSE otherwise.

You are checking whether a boolean (TRUE/FALSE) is equal to the name of your pages. Replace it with the following and it should work:

if (isset($_GET['page']) && $_GET['page'] == 'timeline') { //if page is set and page = timeline
      include("views/timeline.php");

    } else if (isset($_GET['page']) && $_GET['page'] == 'yourtweets') {

        include("views/yourtweets.php");

  } else {
    include("views/home.php");
  }

Hope this helps!

Edit: Sorry @EatPeanutButter, only saw your comment after I posted my answer!

People are also looking for solutions to the problem: php - Can't run INSERT statements on ORACLE with PDO

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.