Link to home
Start Free TrialLog in
Avatar of FairyBusiness
FairyBusinessFlag for United States of America

asked on

Why is my if statement not working?

Hi, I created a function that would only try to include a file if 'type' was in the url:

// Determines which blurb should be included
function blurbs() {
	if(isset($_GET['type'])) {
		$blurb = $_GET['type'];
		$blurb = "include " . $blurb . ".php;";
		return $blurb;
	}
	else {
		return false;
	}
}

Open in new window


but its still trying to include it!!  It should not get past the if statement!?!

anyone know whats going on?

http://gowiththemaster.com/tleithoff/index.php
ASKER CERTIFIED SOLUTION
Avatar of Rik-Legger
Rik-Legger
Flag of undefined image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Marco Gasi
Those message means thast $_GET['type'] is empty: how pass you that value? With a form? Can you show us the form code?
Avatar of FairyBusiness

ASKER

@Rik-Legger  I am still getting the same message

@marqusG  I am not using a form.  I am just trying to include something according to the link that was clicked
I changed it to this:

// Determines which blurb should be included
function blurbs() {
	if(strlen($_GET['type']) > 0) {
		$blurb = $_GET['type'];
		$blurb = $blurb . ".php";
		include $blurb;
	}
	else {
		return false;
	}
}

Open in new window


but still not luck
Then there is a value in $_GET['type'],
if you do like this you can see what it is:

// Determines which blurb should be included
function blurbs() {
        var_dump($_GET['type']); // Debugging
	if(strlen($_GET['type']) > 0) {
		$blurb = $_GET['type'];
		$blurb = "include " . $blurb . ".php;";
		return $blurb;
	}
	else {
		return false;
	}
}

Open in new window

it returns NULL

I will change my code so that it can't be null and see that works
Geez its still not working!!

// Determines which blurb should be included
function blurbs() {
	var_dump($_GET['type']); // Debugging
	if((strlen($_GET['type']) > 0) && (($_GET['type']) != NULL)) {
		$blurb = $_GET['type'];
		$blurb = $blurb . ".php";
		include $blurb;
	}
	else {
		return false;
	}
}

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<?php

include 'header.php';
echo blurbs();
include 'footer.php';

?>

Open in new window

oh wait that was the about.php page!  You were right the index wasnt updated yet!