Results 1 to 3 of 3

Thread: POST, GET or EMPTY problem

  1. #1
    Join Date
    Jul 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question POST, GET or EMPTY problem

    I have a site that every time I do any submit it reload itself and check what it has received. One of the variables I have to look for is the month selected by the user, something like this:
    PHP Code:
    if (empty($_POST['Month'])) {
        
    $mes date("n")-1;
        if (isset(
    $_GET['mes'])){
           
    $mes $_GET['mes'];
        }
    }
    else {
        
    $mes $_POST['Month'];

    I do $mes = date("n")-1 because I use it in order to read an array.

    The problem is that when January is selected, the variable Month (coming from a select in a form) is zero (0) and it is read as empty, so instead of taken the value in the else section, it gets into the if section (if empty).

    If a variable is "0", then it is understood as an empty variable?

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Try using !isset() instead.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jul 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default That's the way

    Somewhere in the php site I read that one of the version of php says that empty('0')=true. I try using isset instead, but if the data is sent with submit button then isset( )=flase. So I send everything so that I just need the isset and never the empty.
    I don't know if this is the best way, but I solved my problem.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •