Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Check that $_post variable exists

Deus_MalumDeus_Malum Posts: 1Member
Hi,
I'm new to php/html and all the seemingly endless tecknowlegy that seems to go with it. I have a html form that may or may not have a particular post variable, when checking the submitted form if the element does not exist it throws a error. I need a way to check if it exists without causing any errors. A further example would be:
If the customer database is using region control a select box would fill with the different regions. If they are not, the select box does not apear (there's nothing to list). So how do I tell on the otherside whether a select box $_POST['regions'] exists without throwing an error?
Thanx a million.

Comments

  • quotientquotient Posts: 62Member
    Pretty simple:[code]if (!isset($_POST['myselectbox'])) print "it does not exists!";[/code]

    The exclamation is used has negation, so if the 'myselectbox' form field is not set (which means NULL), print the message.

    You can do the same, although it is not the preferred method, using[code]if ($_POST['myselectbox'] === NULL) print "it does not exists either!";[/code]

    Good Luck

    Francis
  • mejval85mejval85 Posts: 3Member
    Of course it is possible to check it with [b]empty[/b] statement, eg. like this:
    [code] if (empty($_POST['myselectbox'])) {...} [/code]
  • free_directoryfree_directory Posts: 11Member
    : Hi,
    : I'm new to php/html and all the seemingly endless tecknowlegy
    : that seems to go with it. I have a html form that may or may not
    : have a particular post variable, when checking the submitted form if
    : the element does not exist it throws a error. I need a way to check
    : if it exists without causing any errors. A further example would be:
    : If the customer database is using region control a select box would
    : fill with the different regions. If they are not, the select box
    : does not apear (there's nothing to list). So how do I tell on the
    : otherside whether a select box $_POST['regions'] exists without
    : throwing an error?
    : Thanx a million.
    :
    :
    The best way of doing that's using a native PHP function: array_key_exists :)
    use that way, and you'll never get warnings.
    Read more right here: http://www.php.net/array_key_exists
    it's self explaining, and the best way of doing what you need:)
    Enjoy.
    ---------WEB---------
    Publish your website for free here:
    Real Free Open Directory - http://www.new-dmoz.org
Sign In or Register to comment.