For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > May 2005 > checking if a cell is empty









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author checking if a cell is empty
Ashok

2005-05-23, 8:56 am

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($_POST['helper1_pos'])) {
echo "Sorry! Helper 1 position already volunteered.";
exit;
}
else {
//update
}

Thanks.
Ashok.


J.O. Aho

2005-05-23, 3:56 pm

Ashok wrote:
> 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($_POST['helper1_pos'])) {
> echo "Sorry! Helper 1 position already volunteered.";
> exit;
> }
> else {
> //update
> }



The proper way to check if a varaible is empty is by using the empty()
function, is_null only checks if the value of a variable is null.
Another good funcrtion to use here could be isset(), to see if there is a such
varaible, before you check if it's empty or not.

http://www.php.net/manual/en/function.empty.php
http://www.php.net/manual/en/function.isset.php



//Aho
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com