Forum Moderators: coopster

Message Too Old, No Replies

basic question about PHP include in head

PHP include in head

         

suede1976

8:00 pm on May 8, 2009 (gmt 0)

10+ Year Member



Hi all, i am just just learning PHP and wrote my first if statement and it worked and i thought i was the bees knees, but it turns out it does not in fact work:

I have a basic index page structure like this:

<?php

$page = $_GET['page'];

if (!$page) {
$page = "home";
}

include_once("header.php");
include_once("content/".$page.".php");
include_once("menu.php");
include_once("footer.php");

?>

there are several PHP docs in the contents folder. in the header i want certain scripts only to load with a certain page so i did this in the header.php file:

<?php

if ($page = "portfolio") {
include_once("content/portScripts.php");
}

?>

I was hoping that, the file "portScripts.php" would only load when the page selected had the variable "portfolio" in the URL.

the thing is, it loads "portscripts.php" just fine, but every page has the "portfolio" content, no matter what the $page is in the URL it always comes up portfolio now.

before I added this IF statement to the header.php everything worked just fine. it seems somehow i made the $page variable always be "portfolio"

let me know if i need to include more info.

Thanks!

g1smd

8:34 pm on May 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Change the code
if ($page = "portfolio")
to be this instead
if ($page [b]==[/b] "portfolio")

You need == instead of = here.

suede1976

9:12 pm on May 8, 2009 (gmt 0)

10+ Year Member



Thanks!

coopster

10:30 pm on May 8, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Further reading for clarification between Assignment Operators [php.net] and Comparison Operators [php.net]