0

so I have this really weird bug and I have no idea why it occurs: I have an "index.php" with header and footer and in the middle it includes a "Content.php", that outputs the content, depending on which Get-parameter the index.php has:

if($_GET["site"]){
    switch($_GET["site"]){
        case 1:
            break;
        case 2:
                if($_GET['horses']){
                    include_once("horses.php?horse=".$_GET['horses']);
                } else{
                    include_once("horses.php");
                }
            break;
        case 3: include_once("contact.php");
            break;
        case 4:
                if($_GET['members']){
                    include_once("team.php?member=".$_GET['members']);
                } else{
                    include_once("team.php");
                }
            break;
        case 8: include_once("pressestimmen.php");
            break;
        default: include_once("home.php");
    }
} else{
    include_once("home.php");
}

In some cases (horses and Team members) a second Get-Parameter is passed that is processed inside the corresponding Content-file.
This works perfectly well for the horses and behaves as expected but for some reason, even though I copied the code (except some details) in the "team.php" NO content at all is shown, when I pass a Get-parameter. This in itself wouldn't be too suprising, as I might have a bug in the php somewhere but even when I change team.php to:

<div class="margin-bottom-30">
</div>
<div class="tabs">
    <ul class="nav nav-tabs">

    </ul>
 </div>
 <div class='tab-content'>

</div>

When I call "index.php?site=4" it works without problems and shows the empty containers. But when I call "index.php?site=4&members=1" the Content is completetly empty and I don't understand how this is even possible considering html shouldn't even notice the get parameter.
I've tried to fix this for hours and I just can't figure out how the Get-parameter could possibly affect the html code inside team.php

Juliette
  • 606
  • 7
  • 25

2 Answers2

2

Try changing your case 4 block like this;

case 4:
    include_once("team.php");
    break;

Then in your team.php script, try to get the members parameter from $_GET.

Basically, what you are doing in your implementation, is telling php to look for a file called team.php?member=1 instead of looking for team.php and passing the member = 1 parameter.

Since the file team.php?member=1 (or team.php?member=2, ...) doesn't exists on disk, no content is shown.

If you want detailed information on the errors, warnings, ... on your page (e.g. why a page won't load or what php can't find); add these three lines at the top of your page;

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

Have a look here for more information; How do I get PHP errors to display?

Community
  • 1
  • 1
Stijnster
  • 189
  • 1
  • 6
  • but why does it work for horses then? There it is exactly the same and I even tried to acess the $_GET['horses'] from "horses.php" which didn't work, I could only use the new $_GET['horse'] parameter – Juliette Jul 16 '16 at 06:51
  • Could you double check that? It shouldn't be working for horses either. – Stijnster Jul 16 '16 at 06:52
  • Thanks a lot! I had another bug in the horses file where index.php called ?horse= not ?horses= so I didn't notice that it worked differently there – Juliette Jul 16 '16 at 06:57
  • Awesome! I Just added a bit more information about adding debug code to your script. Maybe that can help in the future? It shows you what errors php runs into when running a script. But **don't forget to turn off those lines once you go in production** as it might show potential security issues!! – Stijnster Jul 16 '16 at 06:59
1

You can not include files like this

include_once("team.php?member=".$_GET['members']);

Just keep include_once("team.php"); and you can access $_GET['members'] value in the team.php if it is set.

Shrikant Mavlankar
  • 1,131
  • 1
  • 8
  • 16
  • Why does it work with horses then though? I have exactly the same include there and inside "horses.php" I can't access $_GET['horses'] like you suggest but only $_GET['horse'] I don't understand why it would work differently with the team tabs – Juliette Jul 16 '16 at 06:53
  • `include_once()` will look for the file name with `team.php?member=1` in your same directory, which does not exist. what you have is `team.php` – Shrikant Mavlankar Jul 16 '16 at 06:56
  • Thanks a lot! I had another bug in the horses file where index.php called ?horse= not ?horses= so I didn't notice that it worked differently there – Juliette Jul 16 '16 at 06:58
  • Try `index.php?site=2&horses=1` you will face the same problem which you are facing for members. – Shrikant Mavlankar Jul 16 '16 at 06:58