I'm sure I'm missing something blindingly obvious here. I am relatively new
to PHP, so excuse dumb mistakes.
I a trying to check a form submitted from an earlier page, and check $_POST
for empty values. Only some of them are not allowed to be empty, hence the
rather lengthy way in which the script is written. If no required fields are
empty, then I want another part of the script to function, and the variables
to be sent to a database. Easy eh? I thought I should be able to simply use
a big 'if ... else' statement. The PHP is at the bottom.
What happens in practice is that PHP is interpreting the first if statement
as always true, even when the $_POST variables are not == "", and the 'else'
part of the PHP never fires. Can anybody spot the idiot mistake I am making?
I have obviously omitted some PHP for ease of reading, but nothing which
should effect the program.
if ($_POST['subscription_r ate'] or $_POST['subscription_t ype'] or
$_POST['first_name'] or $_POST['last_name'] or $_POST['address_street '] ==
"")
{
echo "<table width=\"500\" align=\"center\ " bgcolor=\"white \"><tr><td>\ n
<form target=\"checkb lank.php\" method=\"post\" >";
if ($_POST['subscription_r ate'] == "")
{
echo "part of a form";
}
if ($_POST ['subscription_t ype'] == "")
{
echo "another part of a form";
}
if ($_POST ['first_name'] == "")
{
echo "another part of a form";
}
if ($_POST ['last_name'] == "")
{
echo "another part of a form";
}
if ($_POST ['address_street '] == "")
/*open 2ndary if clause*/
{
echo "another part of a form";
}
echo "<input type=\"reset\" value=\"Reset\" > <input type=\"submit\"
value=\"Submit\ ">\n";
}
else
{
/*submit all the details to MySQL database*/
}
Many thanks for advice
JB
to PHP, so excuse dumb mistakes.
I a trying to check a form submitted from an earlier page, and check $_POST
for empty values. Only some of them are not allowed to be empty, hence the
rather lengthy way in which the script is written. If no required fields are
empty, then I want another part of the script to function, and the variables
to be sent to a database. Easy eh? I thought I should be able to simply use
a big 'if ... else' statement. The PHP is at the bottom.
What happens in practice is that PHP is interpreting the first if statement
as always true, even when the $_POST variables are not == "", and the 'else'
part of the PHP never fires. Can anybody spot the idiot mistake I am making?
I have obviously omitted some PHP for ease of reading, but nothing which
should effect the program.
if ($_POST['subscription_r ate'] or $_POST['subscription_t ype'] or
$_POST['first_name'] or $_POST['last_name'] or $_POST['address_street '] ==
"")
{
echo "<table width=\"500\" align=\"center\ " bgcolor=\"white \"><tr><td>\ n
<form target=\"checkb lank.php\" method=\"post\" >";
if ($_POST['subscription_r ate'] == "")
{
echo "part of a form";
}
if ($_POST ['subscription_t ype'] == "")
{
echo "another part of a form";
}
if ($_POST ['first_name'] == "")
{
echo "another part of a form";
}
if ($_POST ['last_name'] == "")
{
echo "another part of a form";
}
if ($_POST ['address_street '] == "")
/*open 2ndary if clause*/
{
echo "another part of a form";
}
echo "<input type=\"reset\" value=\"Reset\" > <input type=\"submit\"
value=\"Submit\ ">\n";
}
else
{
/*submit all the details to MySQL database*/
}
Many thanks for advice
JB
Comment