<?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 try开发者_运维知识库ing to do if it is true I want to see "it is TRUE" in the screen. Else .....
Take a look at the variables. They don't match:
function control($namecheck1)
{
if ($namecheck == TRUE)
You also never actually invoke that function.
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
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.
It looks as if you are not calling control function.
your are referencing $namecheck in the function "control" but the parameter passed is named $namecheck1. $namecheck in the scope of function "control" is undefined.
Some tips:
- instead
namecheck()
you can useempty()
- before using
$_POST['name']
you should check if it existsisset()
should help
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";
}
?>
精彩评论