| Author |
Problems with error checking / control of POST variables
|
|
| Dariusz 2004-05-21, 7:30 am |
| 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
| |
| Pedro Graca 2004-05-21, 7:30 am |
| 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 :
| |
| Dariusz 2004-05-21, 8:30 am |
| In article <2h642jF98spbU1@uni-berlin.de>, Pedro Graca <hexkid@hotpop.com> wrote:
>Dariusz wrote:
>(snip)
>
>The comparison operator is not "=" !!
The word "Doh !" springs to mind. How I missed that one. Thanks for that.
Dariusz
|
|
|
|