469,926 Members | 1,735 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Problems with error checking / control of POST variables

I have a small form that on button press submits to a PHP file for further
processing into a database. I have to change the script as it allows
blank / nothing to be submitted to the database. The intention is that if
any of the two form fields are blank (empty) then the page is resent
stating that they have to fill in all the fields to post (to a database).

If I deliberately leave the fields blank and submit the form, querying the
database shows that both fields are zero / null - so nothing was entered in
to the database.

However, if I use an echo command to see what is going on (before the data
is entered into a database) I get the $TheName field with a "1" and the
$TheComment field with an unknown entry (it doesn't echo anything to the
screen - but it's not empty).

The code I've used to test this is:

$TheName = $_POST[gbName];
$TheComment = $_POST[gbComment];

if (($TheName = NULL) or ($TheComment = NULL))
{
echo 'Quick error check running:<BR>';
echo "Name: $TheName<BR>";
echo "Comment: $TheComment";
exit;
}

This does NOT execute as these fields are not empty. It only runs if I
change to:

if (($TheName = !NULL) or ($TheComment = !NULL))

Which is pointless as it will always execute with genuine entries.

Using the amended code below:

if (($TheName = !NULL) or ($TheComment = !NULL))
{
echo 'Quick error check running:<BR>';
}

echo "Name: $TheName<BR>";
echo "Comment: $TheComment";
I get the result that both the echoed lines are displayed as blank (no
"1").

Anyone know what's going on?

Dariusz
Jul 17 '05 #1
2 1814
Dariusz wrote:
(snip)
Anyone know what's going on?


The comparison operator is not "=" !!

When you do
if ($a = 7) something();
you're *not* comparing $a to 7 and executing something() if they're equal;

you are assigning 7 to $a, comparing the result of the assignment (which
is 7) to true (which is true) and executing something().
Probably you want to use "==":
if ($a == 7) something();

HTH
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2
In article <2h************@uni-berlin.de>, Pedro Graca <he****@hotpop.com> wrote:
Dariusz wrote:
(snip)
Anyone know what's going on?


The comparison operator is not "=" !!


The word "Doh !" springs to mind. How I missed that one. Thanks for that.

Dariusz
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

55 posts views Thread by drhowarddrfine | last post: by
2 posts views Thread by mb12036 | last post: by
reply views Thread by Henry Reardon | last post: by
17 posts views Thread by Lloyd Sheen | last post: by
2 posts views Thread by akhilesh.noida | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.