date problem...check this out..
Posted: Wed Jul 13, 2005 3:01 am
i have a code here for the date
then on the form
i have 2 calendar functions:
calendar1() and calendar2()
which has an identical code below
the problem now is that whenever i supply the both with different dates, in the database, the end date is reported in the database...for example, if i select July 13 2005 from startdate and July 14 2006, when i open mysql, July 14 2005 is written to both the startdate and enddate fields....another problem is that whenever i leave the startdate blank and supply some data to enddate, again, the enddate is written to the database to both fields, instead of prompting me that i should supply some data to the startdate...but if i did this another way around(leaving enddate blank and supplying some data to startdate), the desired error will be seen...
please help..thanks in advance..
Code: Select all
if (empty($_POST['month']) || empty($_POST['day']) || empty($_POST['year']))
{
$sd = false;
$message .= 'You forgot to enter the project start date<br>';
}
else
{
$sd = $_POST['year']."-".$_POST['month']."-".$_POST['day'];
}
//check for poject duration end date
if (empty($_POST['month']) || empty($_POST['day']) || empty($_POST['year']))
{
$ed = false;
$message .= 'You forgot to enter the project end date<br>';
}
else
{
$ed = $_POST['year']."-".$_POST['month']."-".$_POST['day'];
}
if ($sd && $ed)
{
$query = "INSERT INTO table(startdate, enddate)
VALUES('$sd','$ed');
$result = @mysql_query($query);
if ($result)
{
echo 'project written to database';
echo '<meta http-equiv="refresh" content="3;url=http://localhost/mysample/project.php">';
exit();
}
else
{
echo 'no data was written to the database';
}
mysql_close();
}
else
{
$message .= 'Please try again';
}//end connection to dbCode: Select all
<table width="e;100%"e; cellpadding="e;1"e; cellspacing="e;1"e;>
<tr>
<td width="e;20%"e;><b/>Start Date</td>
<td width="e;80%"e;><? calendar1(); ?></td>
</tr>
<tr>
<td width="e;20%"e;><b/>End Date</td>
<td width="e;80%"e;><? calendar2(); ?></td>
</tr>
</table>calendar1() and calendar2()
which has an identical code below
Code: Select all
function calendar1()
{
//months array
$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
//dropdown
echo '<select name="month">';
echo "<option value=\"\">Month</option><br>";
foreach ($months as $key => $value)
{
echo "<option value=\"$key\">$value</option>\n";
}
echo '</select>
<select name="day">';
echo "<option value=\"\">Day</option><br>";
for ($day = 1; $day <= 31; $day++)
{
echo "<option value=\"$day\">$day</option>\n";
}
echo '</select>
<select name="year">';
echo "<option value=\"\">Year</option><br>";
$year = 2005;
while ($year <= 2010)
{
echo "<option value=\"$year\">$year</option>\n";
$year++;
}
echo '</select>';
}please help..thanks in advance..