I have a simple form,
http://php_class.teamluke.net/Assignment_6/index.php
I tried to create a function that outputs a welcome message only if the form is filled out
<?php
//if the form is filled out, do the create a function & fire it off
if(!empty($_POST))
{
//create welcome message function
function welcome($FirstName) {
if(isset($FirstName)) {
echo "<h1>Welcome ".$FirstName."</h1>";
return true;
} else {
return false;
}
}
//fire off the function
welcome($_POST['FirstName']);
//if the form hasnt been submitted, show it
} else {
?>
...
This is the problem, it will always be set, even if it is set to an empty string, because you are setting it when you call the finction.
You would be better checking for an empty string instead.