Reputation: 11
<?php
$name = $_POST['name'];
$namecheck = namecheck($name);
function namecheck($name){
if(strlen($name)>0)
{
return TRUE;
}
else if(strlen($name)==0)
{
return FALSE;
}
};
function control($namecheck1)
{
if ($namecheck == TRUE)
{
echo "It is TRUE";
}
else if ($namecheck == FALSE)
{
echo "It is FALSE";
}
};
?>
I wrote that there is no problem in HTML part, there is a problem in my php functions because I am new in PHP. Can you make it proper.
I think you will understand what I want to do in the functions its simple Im trying to do if it is true I want to see "it is TRUE" in the screen. Else .....
Upvotes: 1
Views: 10823
Reputation: 11
This works fine
<?php
$name = $_REQUEST['name'];
function namecheck($name1)
{
if(!empty($name1))
{
return TRUE;
}
else
{
return FALSE;
}
}
if (namecheck($name) == TRUE)
{
echo "It is TRUE";
}
else if (namecheck($name) == FALSE)
{
echo "It is FALSE";
}
?>
Upvotes: 0
Reputation: 3539
Some tips:
namecheck()
you can use empty()
$_POST['name']
you should check if it exists isset()
should helpUpvotes: 1
Reputation: 1559
your are referencing $namecheck in the function "control" but the parameter passed is named $namecheck1. $namecheck in the scope of function "control" is undefined.
Upvotes: 1
Reputation: 10838
In your control
function, the parameter is called $namecheck1
at first, but you only call it $namecheck
when you try to use it inside the function.
Upvotes: 1
Reputation: 385098
Take a look at the variables. They don't match:
function control($namecheck1)
{
if ($namecheck == TRUE)
You also never actually invoke that function.
Upvotes: 6
Reputation: 64399
You're not calling your 'control' function. try starting with
$name = $_POST['name'];
$namecheck = namecheck($name);
control($namecheck);
Also, your definition of you function is wrong (or the variable you use is). You can change the function to this
function control($namecheck)
Of the if's to
if ($namecheck1 == TRUE)
in the end the name after control(
is the one you should check for in the if
's
Upvotes: 2