Hi---Can someone out there tell me what's wrong with this code? The date selection boxes are working perfectly (with one exception that the day box starts out with 1 instead of the current or posted day).
The problem comes in when the form submits--now the previous start date value becomes unset. This silly little problem is hanging up my entire event calendar system. Many thanks to whoever can wring this out!
In a simplified, boiled-down version, here it is...
<?php require_once('../Connections/conn_dbname.php');
///////////////////////////////?????
//parts are either set or not set; initialize what's displayed in selection boxes
if (isset($_GET[date])){
$eventDate = $_GET[date];
} else if(isset($_POST['eventDate'])){
$eventDate = $_POST['eventdate'];
} else {
$eventDate = time();
}
$startDate = $eventDate;
////////////////////////???????????????
if(!(isset($_POST['endingDate']))){
$endingDate = $startDate;
}
$day = date('j', $endingDate);
$month = date('n', $endingDate);
$year = date('Y', $endingDate);
//prepares form to display correct dates for months selected
if (isset($_POST['month']) && is_numeric($_POST['month']) &&
((int)$_POST['month'] >= 1 && (int)$_POST['month'] <= 12)) {
$month = (int)$_POST['month'];
} else {
$month = date('n', $endingDate);
}
if (isset($_POST['year']) && is_numeric($_POST['year']) &&
((int)$_POST['year'] >= 2007 && (int)$_POST['year'] <= 2015)) {
$year = (int)$_POST['year'];
} else {
$year = date('Y', $endingDate);
}
///////????? No difference when following code is added
if (isset($_POST['day']) && is_numeric($_POST['day']) &&
((int)$_POST['day'] >= 1 && (int)$_POST['day'] <= 31)) {
$day = (int)$_POST['day'];
} else {
$day = date('j', $endingDate);
}
/////
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><head>
<title></title>
</head>
<table width="100%"><tr><td>
<!--Form for Date Selection-->
<form id="frm_sel_date" name="frm_sel_date" method="POST" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
<input type="hidden" name="startDate" id="startDate" value="<?php echo $_POST['startDate']; ?>" />
<input type="hidden" name="eventDate" id="eventDate" value="<?php echo $_POST['eventDate']; ?>" />
<?php
echo "Date of event is: ". date("Y F d l ", $eventDate) ."<br />"
. "The start date is ". date("Y F d l ", $startDate)."<br /><br />";
?>
<p>Select a date for the ending date:
<select name="day" onChange="this.form.submit();"><?php
$maxdays = date('t', mktime(12, 0, 0, $month, $day, $year));
// if (!(isset($_POST['day']))){
// $day = date("d", $startDate);
// }
for ($i = 1; $i <= $maxdays; $i++) {
if (isset($_POST['day']) && $_POST['day'] == $i) {
$sel = ' selected';
// } elseif ($i == date('j')) {
// $sel = ' selected';
} else {
$sel = '';
}
echo "<option value=\"$i\"$sel>$i</option>\n";
}
?></select>
<select name="month" onChange="this.form.submit();"><?php
for ($i = 1; $i <= 12; $i++) {
if ($month == $i) {
$sel = ' selected';
} else {
$sel = '';
}
$monthname = date('F', mktime(12, 0, 0, $i, 1, $year));
echo "<option value=\"$i\"$sel>$monthname</option>\n";
}
?></select>
<select name="year" onChange="this.form.submit();"><?php
for ($i = 2007; $i <= 2015; $i++) {
if ($year == $i) {
$sel = ' selected';
} else {
$sel = '';
}
echo "<option value=\"$i\"$sel>$i</option>\n";
}
?></select><br />
<?php
$endingDate = date(mktime(12,0,0, $month, $day, $year));
echo "The start date is ".date("Y F d l", $eventDate)."<br />";
echo "The end date is ".date("Y F d l", $endingDate);
?>
</form>
</td></tr></table>
</body>
</html>