469,283 Members | 2,178 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,283 developers. It's quick & easy.

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

Thanks.
Ashok.
Jul 17 '05 #1
5 4736
*** Ashok wrote/escribió (Mon, 23 May 2005 13:36:08 +0400):
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;
}


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
--
Jul 17 '05 #2
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

Jul 17 '05 #3
Change to
if ($_POST["helper1_pos"] == "") {
echo "nothing there blah blah etc etc";
}

"Ashok" <no**@mail.ru> wrote in message news:d6***********@gavrilo.mtu.ru...
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.

Jul 17 '05 #4
or:
if(empty($_POST["helper1_pos"])
echo "nothing here";

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

Jul 17 '05 #5
Ashok napisa³(a):
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.


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
}
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Greg N. | last post: by
3 posts views Thread by Richard | last post: by
6 posts views Thread by tshad | last post: by
TMS
6 posts views Thread by TMS | last post: by
3 posts views Thread by Bill Gower | last post: by
2 posts views Thread by Bart | last post: by
1 post views Thread by =?Utf-8?B?U2F2dm91bGlkaXMgSW9yZGFuaXM=?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.