472,119 Members | 1,556 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

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 5259
*** 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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.