Hi there.
I am trying to do the following:
- User inputs a date into a form and submits the form
- On submission of the form, a PHP Script will calculate how many weeks have passed since that date and redirect them to a page specific to the total.
For example:
I input 12/01/2011
I click Submit
PHP Script calculates that 1 week has passed since that date and redirects me to page1.html
I input 05/01/2011
I click Submit
PHP Script calculates that 2 weeks have passed since that date and redirects me to page2.html
There are 40 pages in total, so the script can redirect me to up to 40 different pages dependent on the number of weeks passed or another page for anything over 40.
This might be complicated… it might be easy. I’ve no idea. I did find 2 tutorials, one for calculating the number of weeks between two dates and 1 for redirecting to a page determined by an if statement. I tried to mash them together but it’s not working.
Can somebody please help me out?
This is what I have so far… but I think it’s probably way off:
<?php
$lmpdate = $_POST['lmpinput'];; // the LMP Date chosen by the user.
$currentDate = mktime(); // Today's date.
$dateSplit = explode("-", $date);
//$dateSplit[0] = Month
//$dateSplit[1] = Day
//$dateSplit[2] = Year
$previousDate = mktime(0, 0, 0, $dateSplit[0], $dateSplit[1], $dateSplit[2]);
$nrSeconds = $currentDate - $previousDate; // substract the previousDate from the currentDate to see how many seconds have passed between these two dates
[B]$nrSeconds = abs($nrSeconds); // in some cases, because of a user input error, the second date which should be smaller then the current one
// will give a negative number of seconds. So we use abs() to get the absolute value of nrSeconds
[/B]
$nrWeeksPassed = floor($nrSeconds / 604800);
}
if($nrWeeksPassed = "1") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup1.html\\">";
}
elseif($nrWeeksPassed = "2") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup2.html\\">";
}
elseif($nrWeeksPassed = "3") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup3.html\\">";
}
elseif($nrWeeksPassed = "4") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup4.html\\">";
}
elseif($nrWeeksPassed = "5") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup5.html\\">";
}
elseif($nrWeeksPassed = "6") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup6.html\\">";
}
elseif($nrWeeksPassed = "7") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup7.html\\">";
}
elseif($nrWeeksPassed = "8") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup8.html\\">";
}
elseif($nrWeeksPassed = "9") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup9.html\\">";
}
elseif($nrWeeksPassed = "10") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup10.html\\">";
}
elseif($nrWeeksPassed = "11") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup11.html\\">";
}
elseif($nrWeeksPassed = "12") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup12.html\\">";
}
elseif($nrWeeksPassed = "13") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup13.html\\">";
}
elseif($nrWeeksPassed = "14") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup14.html\\">";
}
elseif($nrWeeksPassed = "15") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup15.html\\">";
}
elseif($nrWeeksPassed = "16") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup16.html\\">";
}
elseif($nrWeeksPassed = "17") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup17.html\\">";
}
elseif($nrWeeksPassed = "18") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup18.html\\">";
}
elseif($nrWeeksPassed = "19") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup19.html\\">";
}
elseif($nrWeeksPassed = "20") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup20.html\\">";
}
elseif($nrWeeksPassed = "21") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup21.html\\">";
}
elseif($nrWeeksPassed = "22") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup22.html\\">";
}
elseif($nrWeeksPassed = "23") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup23.html\\">";
}
elseif($nrWeeksPassed = "24") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup24.html\\">";
}
elseif($nrWeeksPassed = "25") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup25.html\\">";
}
elseif($nrWeeksPassed = "26") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup26.html\\">";
}
elseif($nrWeeksPassed = "27") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup27.html\\">";
}
elseif($nrWeeksPassed = "28") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup28.html\\">";
}
elseif($nrWeeksPassed = "29") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup29.html\\">";
}
elseif($nrWeeksPassed = "30") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup30.html\\">";
}
elseif($nrWeeksPassed = "31") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup31.html\\">";
}
elseif($nrWeeksPassed = "32") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup32.html\\">";
}
elseif($nrWeeksPassed = "33") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup33.html\\">";
}
elseif($nrWeeksPassed = "34") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup34.html\\">";
}
elseif($nrWeeksPassed = "35") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup35.html\\">";
}
elseif($nrWeeksPassed = "36") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup36.html\\">";
}
elseif($nrWeeksPassed = "37") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup37.html\\">";
}
elseif($nrWeeksPassed = "38") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup38.html\\">";
}
elseif($nrWeeksPassed = "39") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup39.html\\">";
}
elseif($nrWeeksPassed = "40") {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregsignup40.html\\">";
}
else {
echo "<meta http-equiv=\\"refresh\\" content=\\"0;URL=pregnonews.html\\">";
}
endif;
?>
I have also highlighted part of the code above in BOLD because this part I need to change… instead of using “abs” to turn a negative figure into a positive I want an “if” statement that will produce an error if it is a minus figure telling them they need to input a date prior to today’s date.
Lastly, I’m not quite sure how to setup the HTML form to pass the date to the “lmpinput” field in the PHP Script. I need a form where the user will select the Day and Month from drop downs and type the full year (YYYY) into a text field.
I know this sounds like a lot to ask but this is really important so if there is a PHP expert out there who knows how to fix my script… I’d love to hear from you!