Why is my if statement not working?

FairyBusiness
FairyBusiness used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011
Commented:
Try this

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

Open in new window

Marco GasiFreelancer
Top Expert 2010

Commented:
Those message means thast $_GET['type'] is empty: how pass you that value? With a form? Can you show us the form code?

Author

Commented:
@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
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

Author

Commented:
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
Top Expert 2011

Commented:
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

Author

Commented:
it returns NULL

I will change my code so that it can't be null and see that works

Author

Commented:
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

Top Expert 2011
Commented:
I have the idea that it is working but your looking at the wrong lines.
Check for line 4 in the file /home/content/19/7229919/html/tleithoff/index.php.

If you don't see the problem, then paste index.php here.

Author

Commented:
<?php

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

?>

Open in new window

Author

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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial