• Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

PHP help

Spectrum

In need of an oil change
  • 7,399
    Posts
    20
    Years
    Hi, can anybody help me? I was fiddling with my site's layout a while ago, didn't change anything important, and then, my PHP code stopped working.

    <?php
    if ($id == $null) include("home.php");
    else include("$id.php");
    ?>


    Does anybody know why? It's the exact same code I've always used...
     
    You sure your host still supports it? O.o

    I dun see anything wrong with it...
     
    did you accidently delete any files?

    do any of your new files contain an ext different from .php...I dunno either...
     
    Code:
    <?php
    if ($id == [b]null[/b])
         include("home.php");
    else
         include("$id.php");
    ?>

    Unless, you have a previously declared variable, $null, initiated to null ($null=null;), then that wouldn't work. I don't even think that you could name a variable $null in PHP, since it's a predefined keyword.

    Edit: PHP should behave the same way as Java and C++ with the null keyword. You just need to enter "null", since it's not a variable.

    I hope you a 404 page script on your site in case someone tries to enter a bad value for $id. Your script doesn't have a failsafe if block.

    It's also considered better form to oraganise the code as I did (above).
     
    Last edited:
    Yeah, I try to keep my site as organised as possible. And yes my host supports it, all pages on my site are linked by index.php?id=... and when you click the links they show up... I'll try what Hades said, thanks.
     
    Back
    Top