|
Posted by Janwillem Borleffs on 05/23/05 15:48
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;
> }
>
The is_null() function returns only true when the passed argument is
indeed NULL; it doesn't apply to empty strings.
If you want to test for empty strings you should do:
if (!empty($_POST['helper1_pos'])) {
Or even:
if (strlen(trim($_POST['helper1_pos']))) {
to ensure that values consisting of spaces only are considered empty.
When the field will only exist under certain circumstances, you could
also opt to use isset().
JW
Navigation:
[Reply to this message]
|