Question:

How do you check if a POST variable is set?

by  |  earlier

0 LIKES UnLike

when I try:

if (isset($_POST["var"])) {

echo "variable set";

} else {

echo "variable not set";

}

... it returns "variable set" always. Is there another way?

 Tags:

   Report

4 ANSWERS


  1. Im not for sure on this, but I dont think your telling it to go anywhere.

    Try

    IF (isset($_POST["var"])) {

    IF (isset($_POST["/var")) }

    = }

    echo "variable set"

    = {

    echo "variable not set"

    Because you are not skipping the code echo "variable set" it will always come up "variable set"

    What are you trying to do. Please email me if you would like more help.

    Thanks hope it helps,

    Dillon Walker

    dmwalker@dmdwebdesign.net


  2. if isset() does not work for you, try this one

    if ( $_POST["var"] ) {

    echo "variable set";

    } else {

    echo "variable not set";

    }

    hope this helps.

  3. You're doing it the right way, something else must be wrong.

    Are you sure 'var' really isn't set?  Have you tried

    print_r($_POST);

    just prior to the code above?  That way you can see for yourself whether 'var' is set or not.

  4. Try the empty() function

Question Stats

Latest activity: earlier.
This question has 4 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.