1
<?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 .....

0

7 Answers 7

6

Take a look at the variables. They don't match:

function control($namecheck1) 
    {
    if ($namecheck == TRUE) 

You also never actually invoke that function.

Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

1

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.

Comments

1

It looks as if you are not calling control function.

Comments

1

your are referencing $namecheck in the function "control" but the parameter passed is named $namecheck1. $namecheck in the scope of function "control" is undefined.

Comments

1

Some tips:

  • instead namecheck() you can use empty()
  • before using $_POST['name'] you should check if it exists isset() should help

Comments

0

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";
    }

?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.