Andre Dubuc wrote:
Hi,
I'm having problems with a chunk of 'rogue' code that does not perform as
expected (it does not pass the expected date, but an empty value). Most of
the time, it works - so I'm wondering whether it might be a browser issue.
(The latest failure occurred with Firfeox 3.0 browser on an NT 5.1 OS.) The
code is stored on an Unix server, running PHP 5.x.
I've isolated it down to multiple if - elseif statements that check long dates
for completeness, "day" "month" and "year". The code then applies it results
printing one of following: the full date - 22 May 2009, month-year - May
2009, or just the year, 2009. My question is whether the ORDER of checking is
important, i.e, whether checking for the null sets BEFORE full sets or AFTER.
I've added debugging code to be able to get the raw POST values so I can
manually enter it into the db, but I would really appreciate some help here.
The code is old -- I wrote it seven years ago, and had worked well until I
modified it, but I no longer have the original working code.
[The first conditional line of the code checks whether the user has entered
the birth date, then it checks for the death date. The $_SESSION stuff is
debugging code.]
<?php
$yd = $_POST['death'];
$yb = $_POST['birth'];
if ($_POST['bday'] == "Day" && $_POST['bmonth'] == "Month" && $_POST['birth']
== "Year") {
if ($_POST['dday'] != "Day" && $_POST['dmonth'] != "Month" &&
$_POST['death'] != "Year") {
$_POST['rdod'] = ("{$_POST['dday']} {$_POST['dmonth']} {$_POST['death']}");
$_SESSION['ALL1rdod'] = $_POST['rdod'];
}
elseif ($_POST['dday'] == "Day" && $_POST['dmonth'] == "Month" &&
$_POST['death'] != "Year") {
$_POST['rdod'] = $_POST['death'];
$_SESSION['YEAR1rdod'] = $_POST['rdod'];
}
elseif ($_POST['dday'] == "Day" && $_POST['dmonth'] != "Month" &&
$_POST['death'] != "Year") {
$_POST['rdod'] = ("{$_POST['dmonth']} {$_POST['death']}");
$_SESSION['MONTHYEAR1rdod'] = $_POST['rdod'];
}
$_SESSION['Sdebugdod1'] = "{$_POST['dday']} {$_POST['dmonth']}
{$_POST['death']}";
}
else {
if ($yd > $yb) {
if ($_POST['bday'] != "Day" && $_POST['bmonth'] != "Month" &&
$_POST['birth'] != "Year") {
$_POST['rdob'] = ("{$_POST['bday']} {$_POST['bmonth']}
{$_POST['birth']}");
}
elseif ($_POST['bday'] == "Day" && $_POST['bmonth'] == "Month" &&
$_POST['birth'] != "Year") {
$_POST['rdob'] = $_POST['birth'];
}
elseif ($_POST['bday'] == "Day" && $_POST['bmonth'] != "Month" &&
$_POST['birth'] != "Year") {
$_POST['rdob'] = ("{$_POST['bmonth']} {$_POST['birth']}");
}
if ($_POST['dday'] != "Day" && $_POST['dmonth'] != "Month" &&
$_POST['death'] != "Year") {
$_POST['rdod'] = ("{$_POST['dday']} {$_POST['dmonth']}
{$_POST['death']}");
$_SESSION['ALL2rdod'] = $_POST['rdod'];
}
elseif ($_POST['dday'] == "Day" && $_POST['dmonth'] == "Month" &&
$_POST['death'] != "Year") {
$_POST['rdod'] = $_POST['death'];
$_SESSION['YEAR2rdod'] = $_POST['rdod'];
}
elseif ($_POST['dday'] == "Day" && $_POST['dmonth'] != "Month" &&
$_POST['death'] != "Year") {
$_POST['rdod'] = ("{$_POST['dmonth']} {$_POST['death']}");
$_SESSION['MONTHYEAR2rdod'] = $_POST['rdod'];
}
$_SESSION['Sdebugdod2'] = "{$_POST['dday']} {$_POST['dmonth']}
{$_POST['death']}";
}
?>
Any help or pointers would be greatly appreciated!
Tia,
Andre
makes no sense at all to me without some decent variable names "rdod"? -
would also need the form to be honest, and a description of the
functionality needed.
one thing i can say is that you have a closing bracket missing at the
end and your $_SESSION['Sdebugdod2'] appears to be in the wrong place
(to solve both these try sticking a } before $_SESSION['Sdebugdod2']
really though, change the names in the form to something more descriptive
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php