compare value of cell

This is a discussion on compare value of cell within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi, I need a condition in update form where before the form is updated, I have to check if the ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-23-2005
Ashok
 
Posts: n/a
Default compare value of cell

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.


Reply With Quote
  #2 (permalink)  
Old 05-23-2005
Janwillem Borleffs
 
Posts: n/a
Default Re: compare value of cell

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

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:13 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0