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
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
Comment