checking if a cell is empty

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ashok

    checking if a cell is empty

    Hi,
    I need a condition in update form where before the form is updated, I have
    to check if the value of a cell is empty or not. If it is not empty, an
    error is shown and if empty, it is updated.
    What I am doing wrong in the script ( $_POST['helper1_pos'] gets value from
    the form). It shows error even if the cell is empty.

    if (!is_null($_POS T['helper1_pos'])) {
    echo "Sorry! Helper 1 position already volunteered.";
    exit;
    }
    else {
    //update
    }

    Thanks.
    Ashok.


  • Alvaro G Vicario

    #2
    Re: checking if a cell is empty

    *** Ashok wrote/escribió (Mon, 23 May 2005 13:36:08 +0400):[color=blue]
    > What I am doing wrong in the script ( $_POST['helper1_pos'] gets value from
    > the form). It shows error even if the cell is empty.
    >
    > if (!is_null($_POS T['helper1_pos'])) {
    > echo "Sorry! Helper 1 position already volunteered.";
    > exit;
    > }[/color]

    PHP does not set to NULL post variables when they're empty. You can merely
    check if they're empty strings (because, in the end, all form fields are
    sent as strings).


    --
    -- Álvaro G. Vicario - Burgos, Spain
    -- http://bits.demogracia.com - Mi sitio sobre programación web
    -- Don't e-mail me your questions, post them to the group
    --

    Comment

    • Aaron Askew

      #3
      Re: checking if a cell is empty

      Per the manual, a variable is considered to be NULL if

      *it has been assigned the constant NULL.
      *it has not been set to any value yet.
      *it has been unset().

      I'm guessing $_POST['helper1_pos'] is being set to an empty string or
      something.

      -aaron

      Comment

      • Kelvin Chu

        #4
        Re: checking if a cell is empty

        Change to
        if ($_POST["helper1_po s"] == "") {
        echo "nothing there blah blah etc etc";
        }

        "Ashok" <non2@mail.ru > wrote in message news:d6s85r$152 g$1@gavrilo.mtu .ru...[color=blue]
        > Hi,
        > I need a condition in update form where before the form is updated, I have
        > to check if the value of a cell is empty or not. If it is not empty, an
        > error is shown and if empty, it is updated.
        > What I am doing wrong in the script ( $_POST['helper1_pos'] gets value[/color]
        from[color=blue]
        > the form). It shows error even if the cell is empty.
        >
        > if (!is_null($_POS T['helper1_pos'])) {
        > echo "Sorry! Helper 1 position already volunteered.";
        > exit;
        > }
        > else {
        > //update
        > }
        >
        > Thanks.
        > Ashok.
        >
        >[/color]


        Comment

        • ZeldorBlat

          #5
          Re: checking if a cell is empty

          or:
          if(empty($_POST["helper1_po s"])
          echo "nothing here";

          Although that if statement will evaluate to true if the box contains
          the string "0".

          Comment

          • elessar

            #6
            Re: checking if a cell is empty

            Ashok napisa³(a):[color=blue]
            > Hi,
            > I need a condition in update form where before the form is updated, I have
            > to check if the value of a cell is empty or not. If it is not empty, an
            > error is shown and if empty, it is updated.
            > What I am doing wrong in the script ( $_POST['helper1_pos'] gets value from
            > the form). It shows error even if the cell is empty.
            >
            > if (!is_null($_POS T['helper1_pos'])) {
            > echo "Sorry! Helper 1 position already volunteered.";
            > exit;
            > }
            > else {
            > //update
            > }
            >
            > Thanks.
            > Ashok.
            >
            >[/color]

            Hi,

            function is_null give true when $_POST['helper1_pos'] = NULL.
            You must understand NULL is not ''.

            use function empty()

            if (empty($_POST['helper1_pos'])) {
            echo "Sorry! Helper 1 position already volunteered.";
            exit;
            }
            else {
            //update
            }

            Comment

            Working...