Page 1 of 1

date retrieval from form to mysql...again

Posted: Thu Jul 07, 2005 4:32 am
by pleigh
can somebody help me build a simple code retrieving a date from a form to be stored in mysql??initially, i have a calendar function, but i'm stuck on how i can retrieve the value of the dates to be stored in the database...below is my function...and i'm stuck from here...

Code: Select all

function calendar()
{
	//months arraw
	$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	
	//dropdown
	echo '<select name="month">';
	foreach ($months as $key => $value) {
		echo "<option value=\"$key\">$value</option>\n";
	}
	echo '</select>
	<select name="day">';
	for ($day = 1; $day <= 31; $day++) {
		echo "<option value=\"$day\">$day</option>\n";
	}
	echo '</select>
	<select name="year">';
	$year = 2003;
	while ($year <= 2010) {
		echo "<option value=\"$year\">$year</option>\n";
		$year++;
	}
	echo '</select>';
}
by the way...i only copied the code from my book...thanks in advance :)red in the database...below is my function...and i'm stuck from here...

Code: Select all

function calendar()
{
	//months arraw
	$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	
	//dropdown
	echo '<select name="month">';
	foreach ($months as $key => $value) {
		echo "<option value=\"$key\">$value</option>\n";
	}
	echo '</select>
	<select name="day">';
	for ($day = 1; $day <= 31; $day++) {
		echo "<option value=\"$day\">$day</option>\n";
	}
	echo '</select>
	<select name="year">';
	$year = 2003;
	while ($year <= 2010) {
		echo "<option value=\"$year\">$year</option>\n";
		$year++;
	}
	echo '</select>';
}
by the way...i only copied the code from my book...thanks i
echo '</select>
<select name="day">';
for ($day = 1; $day &lt;= 31; $day++) {
echo &quote;&lt;option value=\&quote;$day\&quote;&gt;$day&lt;/option&gt;\n&quote;;
}
echo '</select>
<select name="year">';
$year = 2003;
while ($year <= 2010) {
echo "&amfrom a form to be stored in mysql??initially, i have a calendar function, but i'm stuck on how i can retrieve the value of the dates to be stored in the database...below is my function...and i'm stuck from here...

Code: Select all

function calendar()
{
	//months arraw
	$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	
	//dropdown
	echo '<select name="month">';
	foreach ($months as $key =&gt; $value) {
		echo &quote;&lt;option value=\&quote;$key\&quote;&gt;$value&lt;/option&gt;\n&quote;;
	}
	echo '&lt;/select&gt;
	&lt;select name=&quote;day&quote;&gt;';
	for ($day = 1; $day &lt;= 31; $day++) {
		echo &quote;&lt;option value=\&quote;$day\&quote;&gt;$day&lt;/option&gt;\n&w i can retrieve the value of the dates to be stored in the database...below is my function...and i'm stuck from here...

Code: Select all

function calendar()
{
	//months arraw
	$months = array (1 =&gt; 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	
	//dropdown
	echo '&lt;select name=&quote;month&quote;&gt;';
	foreach ($months as $key =&gt; $value) {
		echo &quote;&lt;option value=\&quote;$key\&quote;&gt;$value&lt;/option&gt;\n&quote;;
	}
	echo '&lt;/select&gt;
	&lt;select name=&quote;day&quote;&gt;';
	for ($day = 1; $day &lt;= 31; $day++) {
		echo &quote;&lt;option value=\&quote;$day\&quote;&gt;$day&lt;/option&gt;\n&quote;;
	}
	echo '&lt;/select&gt;
	&lt;select name=&quote;year&quote;&gt;';
	$year = 2003;
	while ($year &lt;= 2010) {
		echo &quote;&lt;option value=\&quote;$year\&quote;&gt;$year&lt;/option&gt;\n&quote;;
		e from a form to be stored in mysql??initially, i have a calendar function, but i'm stuck on how i can retrieve the value of the dates to be stored in the database...below is my function...and i'm stuck from here...

Code: Select all

function calendar()
{
	//months arraw
	$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	
	//dropdown
	echo '<select name="month">';
	foreach ($months as $key => $value) {
		echo "<option value=\"$key\">$value</option>\n";
	}
	echo '</select>
	<select name="day">';
	for ($day = 1; $day <= 31; $day++) {
		echo "<option value=\"$day\">$day</option>\n";
	}
	echo '</select>
	<select name="year">';
	$year = 2003;
	while ($year <= 2010) {
		echo "<option value=\"$year\">$year</option>\n";
		$year++;
	}
	echo '</select>';
}
by the way...i only copied the code from my book...thanks in advance :) name="month">';
foreach ($months as $key => $value) {
echo "<option value=\"$key\">$value</option>\n";
}
echo '</select>
<select name="day">';
for ($day = 1; $day <= 31; $day++) {
echo "<option value=\"$day\">$day</option>\n";
}
echo '</select>
<select name="year">';
$year = 2003;
while ($year <= 2010) {
echo "<option value=\"$year\">$year</option>\n";
$year++;
}
echo '</select>';
}
[/ph<select name="month">';
foreach ($months as $key => $value) {
echo "<option value=\"$key\">$value</option>\n";
}
echo '</select>
<select name="day">';
for ($day = 1; $day <= 31; $day++) {
echo "<option value=\"$day\">$day</option>\n";
}
echo '</select>
<select name="year">';
$year = 2003;
while ($year <= 2010) {
echo "<option value=\"$year\">$year</option>\n";
$year++;
}
echo '</select>';
}


by the way...i only copied the code from my book...thanks in advance :), but i'm stuck on how i can retrieve the value of the dates to be stored in the database...below is my function...and i'm stuck from here...

Code: Select all

function calendar()
{
	//months arraw
	$months = array (1 =&gt; 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	
	//dropdown
	echo '&lt;select name=&quote;month&quote;&gt;';
	foreach ($months as $key =&gt; $value) {
		echo &quote;&lt;option value=\&quote;$key\&quote;&gt;$value&lt;/option&gt;\n&quote;;
	}
	echo '&lt;/select&gt;
	&lt;select name=&quote;day&quote;&gt;';
	for ($day = 1; $day &lt;= 31; $day++) {
		echo &quote;&lt;option value=\&quote;$day\&quote;&gt;$day&lt;/option&gt;\n&quote;;
	}
	echo '&lt;/select&gt;
	&lt;select name=&quote;year&quote;&gt;';
	$year = 2003;
	while ($year &lt;= 2010) {
		echo &quote;&lt;option value=\&quote;$year\&quote;&gt;$year&lt;/option&gt;\n&quote;;
tuck on how i can retrieve the value of the dates to be stored in the database...below is my function...and i'm stuck from here...

Code: Select all

function calendar()
{
	//months arraw
	$months = array (1 =&gt; 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	
	//dropdown
	echo '&lt;select name=&quote;month&quote;&gt;';
	foreach ($months as $key =&gt; $value) {
		echo &quote;&lt;option value=\&quote;$key\&quote;&gt;$value&lt;/option&gt;\n&quote;;
	}
	echo '&lt;/select&gt;
	&lt;select name=&quote;day&quote;&gt;';
	for ($day = 1; $day &lt;= 31; $day++) {
		echo &quote;&lt;option value=\&quote;$day\&quote;&gt;$day&lt;/option&gt;\n&quote;;
	}
	echo '&lt;/select&gt;
	&lt;select name=&quote;year&quote;&gt;';
	$year = 2003;
	while ($year &lt;= 2010) {
		ecme build a simple code retrieving a date from a form to be stored in mysql??initially, i have a calendar function, but i'm stuck on how i can retrieve the value of the dates to be stored in the database...below is my function...and i'm stuck from here...

Code: Select all

function calendar()
{
	//months arraw
	$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	
	//dropdown
	echo '<select name="month"&gt;';
	foreach ($months as $key =&gt; $value) {
		echo &quote;&lt;option value=\&quote;$key\&quote;&gt;$value&lt;/option&gt;\n&quote;;
	}
	echo '&lt;/select&gt;
	&lt;select name=&quote;day&quote;&gt;';
	for ($day = 1; $day &lt;= 31; $day++) {
		echo &quote;&lt;option value=\&qu code retrieving a date from a form to be stored in mysql??initially, i have a calendar function, but i'm stuck on how i can retrieve the value of the dates to be stored in the database...below is my function...and i'm stuck from here...

Code: Select all

function calendar()
{
	//months arraw
	$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	
	//dropdown
	echo '&lt;select name=&quote;month&quote;&gt;';
	foreach ($months as $key =&gt; $value) {
		echo &quote;&lt;option value=\&quote;$key\&quote;&gt;$value&lt;/option&gt;\n&quote;;
	}
	echo '&lt;/select&gt;
	&lt;select name=&quote;day&quote;&gt;';
	for ($day = 1; $day &lt;= 31; $day++) {
		echo &quote;&lt;option value=\&quote;$day\&quote;&gt;$day&lt;/option&gt;\n&quote;;
	}
	echo '&lt;/select&gt;
	&lt;select name=&quote;year&quote;&gt;';
	$year = 2003;
	while ($year &lt;= 2010) {
		echo &quote;&lt;option value=\&quote;$yeartuck from here...

Code: Select all

function calendar()
{
	//months arraw
	$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	
	//dropdown
	echo '&lt;select name=&quote;month&quote;&gt;';
	foreach ($months as $key =&gt; $value) {
		echo &quote;&lt;option value=\&quote;$key\&quote;&gt;$value&lt;/option&gt;\n&quote;;
	}
	echo '&lt;/select&gt;
	&lt;select name=&quote;day&quote;&gt;';
	for ($day = 1; $day &lt;= 31; $day++) {
		echo &quote;&lt;option value=\&quote;$day\&quote;&gt;$day&lt;/option&gt;\n&quote;;
	}
	echo '&lt;/select&gt;
	&lt;select name=&quote;year&quote;&gt;';
	$year = 2003;
	while ($year &lt;= 2010) {
		echo &quote;&a..below is my function...and i'm stuck from here...

Code: Select all

function calendar()
{
	//months arraw
	$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	
	//dropdown
	echo '<select name="month">';
	foreach ($months as $key => $value) {
		echo "<option value=\"$key\">$value</option>\n";
	}
	echo '</select>
	<select name="day">';
	for ($day = be stored in mysql??initially, i have a calendar function, but i'm stuck on how i can retrieve the value of the dates to be stored in the database...below is my function...and i'm stuck from here...

Code: Select all

function calendar()
{
	//months arraw
	$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	
	//dropdown
	echo '<select name="month">';
	foreach ($months as $key => $value) {
		echo "<option value=\"$key\">$value</option>\n";
	}
	echo '</select>
	<select name="day">';
	for ($day = 1; $day <= 31; $day++) {
		echo "<option value=\"$day\">$day</option>\n";
	}
	echo '</select>
	<select name="year">';
	$year = 2003;
	while ($year <= 2010) {
		echo "<option value=\"$year\">$year</option>\n";
		$year++;
	}
	echo '</select>';
}
by the way...i only copied the code from my book...thanks in advance :)here...

Code: Select all

function calendar()
{
	//months arraw
	$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	
	//dropdown
	echo '<select name=&quote;month&quote;&gt;';
	foreach ($months as $key =&gt; $value) {
		echo &quote;&lt;option value=\&quote;$key\&quote;&gt;$value&lt;/option&gt;\n&quote;;
	}
	echo '&lt;/select&gt;
	&lt;select name=&quote;day&quote;&gt;';
	for ($day = 1; $day &lt;= 31; $day++) {
		echo &quote;&lt;option value=\&quote;$day\&quote;&gt;$day&lt;/option&gt;\n&quote;;
	}
	echo '&l, i have a calendar function, but i'm stuck on how i can retrieve the value of the dates to be stored in the database...below is my function...and i'm stuck from here...

Code: Select all

function calendar()
{
	//months arraw
	$months = array (1 =&gt; 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	
	//dropdown
	echo '&lt;select name=&quote;month&quote;&gt;';
	foreach ($months as $key =&gt; $value) {
		echo &quote;&lt;option value=\&quote;$key\&quote;&gt;$value&lt;/option&gt;\n&quote;;
	}
	echo '&lt;/select&gt;
	&lt;select name=&quote;day&quote;&gt;';
	for ($day = 1; $day &lt;= 31; $day++) {
		echo &quote;&lt;option value=\&quote;$day\&quote;&gt;$day&lt;/option&gt;\n&quote;;
	}
	echo '&lt;/select&gt;
	&lt;select name=&quote;year&quote;&gt;';
	$year = 2003;
	while ($year &lt;= 2010) {
		echo &quote;&lt;option value=\&quote;$year\&quome build a simple code retrieving a date from a form to be stored in mysql??initially, i have a calendar function, but i'm stuck on how i can retrieve the value of the dates to be stored in the database...below is my function...and i'm stuck from here...

Code: Select all

function calendar()
{
	//months arraw
	$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	
	//dropdown
	echo '<select name="month">';
	foreach ($months as $key => $value) {
		echo "<option value=\"$key\">$value</option>\n";
	}
	echo '</select>
	<select name="day">';
	for ($day = 1; $day <= 31; $day++) {
		echo "<option value=\"$day\">$day</option>\n";
	}
	echo '</select>
	<select name="year">';
	$year = 2003;
	while ($year <= 2010) {
		echo "<option value=\"$year\">$year</option>\n";
		$year++;
	}
	echo '</select>';
}
by the way...i only copied the code from my book...thanks in advance :)

Posted: Thu Jul 07, 2005 5:15 am
by harrisonad
haha..
that's what bugs me when i first used that technique.
If you want to retrieve the value of your select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
ay and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
e.
If you want to retrieve the value of your select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
ey are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST&#1111;'year'].'-'.$_POST&#1111;'month'].'-'.$_POST&#1111;'day'];
// which gives 2005-07-07, compatible with MySQL
// orque.
If you want to retrieve the value of your select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
tible with MS SQL
m as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST&#1111;'month'].'-'.$_POST&#1111;'day'];
// which gives 2005-07-07, compatible with MySQL
//p since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POSt bugs me when i first used that technique.
If you want to retrieve the value of your select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
first used that technique.
If you want to retrieve the value of your select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
3ba5f299b]
$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
//s how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
to retrieve the value of your select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL

Posted: Thu Jul 07, 2005 5:17 am
by harrisonad
Here is my version of the same function for date input

Code: Select all

function DateSelectionBoxes($date='',$name='date'){
	if($date=='') $date = date("Y-m-d");
    $date_array = explode("-",$date);
    $yr = $date_array[0];
    $mn = $date_array[1];
    $dy = $date_array[2];
	settype($yr,'int');
	settype($mn,'int');
	settype($dy,'int');

	$lastday = 31;
    if(checkdate($mn,31,$yr)) $lastday = 31;
    elseif(checkdate($mn,30,$yr)) $lastday = 30;
    elseif(checkdate($mn,29,$yr)) $lastday = 29;
    elseif(checkdate($mn,28,$yr)) $lastday = 28;

    $str_year = "<input class=box type='text'
		name='".$name."_year' size=1 maxlength=4 value='".$yr."'
		onblur=\" 
			if(this.value.length<4){
				var dt = new Date();
				this.value = dt.getYear();
			}\">";
    $str_day = "<select class=box name='".$name."_day'>";
    for($i=1;$i<=$lastday;$i++){
            $str_day .= "<option value=".$i;
            if($i==$dy) $str_day .= " selected";
            $str_day .= ">".$i."</option>";
    }
    $str_day .= "</SELECT>";
    $str_month = "
		<SELECT name='".$name."_month' class=box style='scrollbar-face-color: black'>
		<option value=1".($mn==1?' selected':'').">January
		<option value=2".($mn==2?' selected':'')."&amay = explode("-",$date);
    $yr = $date_array[0];
    $mn = $date_array[1];
    $dy = $date_array[2];
	settype($yr,'int');
	settype($mn,'int');
	settype($dy,'int');

	$lastday = 31;
    if(checkdate($mn,31,$yr)) $lastday = 31;
    elseif(checkdate($mn,30,$yr)) $lastday = 30;
    elseif(checkdate($mn,29,$yr)) $lastday = 29;
    elseif(checkdate($mn,28,$yr)) $lastday = 28;

    $str_year = "<input class=box type='text'
		name='".$name."_year' size=1 maxlength=4 value='".$yr."'
		onblur=\" 
			if(this.value.length<4){
				var dt = new Date();
				this.value = dt.getYear();
			}\">";
    $str_day = "<select class=box name='".$name."_day'>";
    for($i=1;$i<=$lastday;$i++){
            $str_day .= "<option value=".$i;
            if($i==$dy) $str_day .= " selected";
            $str_day .= ">".$i."</option>";
    }
    $str_day .= "</SELECT>";
    $str_month = "
		<SELECT name='".$name."_month' class=box style='scrollbar-face-color: black'>
		<option value=1".($mn==1?' selected':'').">January
		<option value=2".($mn==2?' selected':'').">February
		<option value=3".($mn==3?' selected':'').">March
		<option value=4".($mn==4?' selected':'').">April
		<option value=5".($mn==5?' selected':'').">May
		<option value=6".($mn==6?' selected':'').">June
		<option value=7".($mn==7?' selected':'').">July
		<option value=8".($mn==8?' selected':'').">August
		<option value=9".($mn==9?' selected':'').">September
		<option value=10".($mn==10?' selected':'').">October
		<option value=11".($mn==11?' selected':'').">November
		<option value=12".($mn==12?' selected':'').">December
		</SELECT>";

    return $str_month." ".$str_day.", ".$str_year;
}
Note that the year field is a textbox forte;.$yr."'
onblur=\"
if(this.value.length<4){
var dt = new Date();
this.value = dt.getYear();
}\&quote;&gt;&quote;;
$str_day = &quote;&lt;select class=box name='&quote;.$name.&quote;_day'>";
for($i=1;$i<=$lastday;$i++){
$str_day .= "<option value=".$i;
if($i==$dy) $str_day .= " selected&quote;;
$str_day .= &quote;&gt;&quote;.$i.&quote;&lt;/option&gt;&quote;;
}
$str_day .= &quote;&lt;/SELECT&gt;&quote;;
$str_month = &quote;
&lt;SELECT name='&quote;.$name.&quote;_month' class=box style='scrollbar-face-color: black'&gt;
&lt;option value=1&quote;.($mn==1?' selected':'').&quote;&gt;January
&lt;option value=2&quote;.($mn==2?' selected':'').&quote;&amp]
function DateSelectionBoxes($date='',$name='date'){
if($date=='') $date = date("Y-m-d");
$date_array = explode("-",$date);
$yr = $date_array[0];
$mn = $date_array[1];
$dy = $date_array[2];
settype($yr,'int');
settype($mn,'int');
settype($dy,'int');

$lastday = 31;
if(checkdate($mn,31,$yr)) $lastday = 31;
elseif(checkdate($mn,30,$yr)) $lastday = 30;
elseif(checkdate($mn,29,$yr)) $lastday = 29;
elseif(checkdate($mn,28,$yr)) $lastday = 28;

$str_year = &quote;&lt;input class=box type='text'
name='&quote;.$name.&quote;_year' size=1 maxlength=4 value='&quote;.$yr.&quote;'
onblur=\&quote;
if(this.value.length&lt;4){
var dt = new Date();
this.value = dt.getYear();
}\&quote;&gt;&quote;;
$str_day = &quote;&lt;select class=box name='&quote;.$name.&quote;_day'&gt;&quote;;
for($i=1;$i&lt;=$lastday;$i++){
$str_day .= &quote;&lt;option value=&quote;.$i;
if($i==$dy) $str_day .= &quote; selected&quote;;
$str_day .= &quote;&gt;&quote;.$i.&quote;&lt;/option&gt;&quote;;
}
$str_day .= &quote;&lt;/SELECT&gt;&quote;;
$str_month = &quote;
&lt;SELECT name='&quote;.$name.&quote;_month' class=box style='scrollbar-face-color: black'&gt;
&lt;option value=1&quote;.($mn==1?' selected':'').&quote;&gt;January
&lt;option value=2&quote;.($mn==2?' selected':'').&quote;&gt;February
&lt;option value=3&quote;.($mn==3?' selected':'').&quote;&gt;March
&lt;option value=4&quote;.($mn==4?' selected':'').&quote;&gt;April
&lt;option value=5&quote;.($mn==5?' selected':'').&quote;&gt;May
&lt;option value=6&quote;.($mn==6?' selected':'').&quote;&gt;June
&lt;option value=7&quote;.($mn==7?' selected':'').&quote;&gt;July
&lt;option value=8&quote;.($mn==8?' selected':'').&quote;&gt;August
&lt;option value=9&quote;.($mn==9?' selected':'').&quote;&gt;September
&lt;option value=10&quote;.($mn==10?date("Y-m-d");
$date_array = explode(&quote;-&quote;,$date);
$yr = $date_arrayї0];
$mn = $date_arrayї1];
$dy = $date_arrayї2];
settype($yr,'int');
settype($mn,'int');
settype($dy,'int');

$lastday = 31;
if(checkdate($mn,31,$yr)) $lastday = 31;
elseif(checkdate($mn,30,$yr)) $lastday = 30;
elseif(checkdate($mn,29,$yr)) $lastday = 29;
elseif(checkdate($mn,28,$yr)) $lastday = 28;

$str_year = &quote;&lt;input class=box type='text'
name='&quote;.$name.&quote;_year' size=1 maxlength=4 value='&quote;.$yr.&quote;'
onblur=\&quote;
if(this.value.length&lt;4){
var dt = new Date();
this.value = dt.getYear();
}\&quote;&gt;&quote;;
$str_day = &quote;&lt;select class=box name='&quote;.$name.&quote;_day'&gt;&quote;;
for($i=1;$i&lt;=$lastday;$i++){
$str_day .= &quote;&lt;option value=&quote;.$i;
if($i==$dy) $str_day .= &quote; selected&quote;;
$str_day .= &quote;&gt;&quote;.$i.&quote;&lt;/option&gt;&quote;;
}
$str_day .= &quote;&lt;/SELECT&gt;&quote;;
$str_month = &quote;
&lt;SELECT name='&quote;.$name.&quote;_month' class=box style='scrollbar-face-color: black'&gt;
&lt;option value=1&quote;.($mn==1?' selected':'').&quote;&gt;January
&lt;option value=2&quote;.($mn==2?' selected':'').&quote;&gt;February
&lt;option value=3&quote;.($mn==3?' selected':'').&quote;&gt;March
&lt;option value=4&quote;.($mn==4?' selected':'').&quote;&gt;April
&lt;option value=5&quote;.($mn==5?' selected':'').&quote;&gt;May
&lt;option value=6&quote;.($mn==6?' selected':'').&quote;&gt;June
&lt;option value=7&quote;.($mn==7?' selected':'').&quote;&gt;July
&lt;option value=8&quote;.($mn==8?' selected':'').&quote;&gt;August
&lt;option value=9&quote;.($mn==9?' selected':'').&quote;&gt;September
&lt;option value=10&quote;.($mn==10?' selected':'').&quote;&gt;October
&lt;option value=11&quote;.($mn==11?' selected':'').&quote;&gt;November
&lt;option value=12&quote;.($mn==12?' selected':'').&quote;&gt;December
&lt;/SELECT&gt;&quote;;

return $str_php]
function DateSelectionBoxes($date='',$name='date'){
if($date=='') $date = date("Y-m-d");
$date_array = explode("-",$date);
$yr = $date_array[0];
$mn = $date_array[1];
$dy = $date_array[2];
settype($yr,'int');
settype($mn,'int');
settype($dy,'int');

$lastday = 31;
if(checkdate($mn,31,$yr)) $lastday = 31;
elseif(checkdate($mn,30,$yr)) $lastday = 30;
elseif(checkdate($mn,29,$yr)) $lastday = 29;
elseif(checkdate($mn,28,$yr)) $lastday = 28;

$str_year = "<input class=box type='text'
name='".$name."_year' size=1 maxlength=4 value='".$yr."'
onblur=\"
if(this.value.length<4){
var dt = new Date();
this.value = dt.getYear();
}\">";
$str_day = "<select class=box name='".$name."_day'>";
for($i=1;$i<=$lastday;$i++){
$str_day .= "<option value=".$i;
if($i==$dy) $str_day .= " selected";
$str_day .= ">".$i."</option>";
}
$str_day .= "</SELECT>";
$str_month = "
<SELECT name='".$name."_month' class=box style='scrollbar-face-color: black'>
<option value=1".($mn==1?' selected':'').">January
<option value=2".($mn==2?' selected':'')f(checkdate($mn,29,$yr)) $lastday = 29;
elseif(checkdate($mn,28,$yr)) $lastday = 28;

$str_year = "<input class=box type='text'
name='".$name."_year' size=1 maxlength=4 value='".$yr."'
onblur=\"
if(this.value.length<4){
var dt = new Date();
this.value = dt.getYear();
}\">";
$str_day = "<select class=box name='".$name."_day'>";
for($i=1;$i<=$lastday;$i++){
$str_day .= "<option value=".$i;
if($i==$dy) $str_day .= " selected";
$str_day .= ">".$i."</option>";
}
$str_day .= "&lt;/SELECT&gt;&quote;;
$str_month = &quote;
&lt;SELECT name='&quote;.$name.&quote;_month' class=box style='scrollbar-face-color: black'&gt;
&lt;option value=1&quote;.($mn==1?' selected':'').&quote;&gt;January
&lt;option value=2&quote;.($mn==2?' selected':'').&quote;&gt;February
&lt;option value=3&quote;.($mn==3?' selected':'').&quote;&gt;March
&lt;option value=4&quote;.($mn==4?' selected':'').&quote;&gt;April
&lt;option value=5&quote;.($mn==5?' selected':'').&quoy = 30;
elseif(checkdate($mn,29,$yr)) $lastday = 29;
elseif(checkdate($mn,28,$yr)) $lastday = 28;

$str_year = "<input class=box type='text'
name='".$name."_year' size=1 maxlength=4 value='".$yr."'
onblur=\"
if(this.value.length<4){
var dt = new Date();
this.value = dt.getYear();
}\">";
$str_day = "<select class=box name='".$name."_day'>";
for($i=1;$i<=$lastday;$i++){
$str_day .= "<option value=".$i;
if($i==$dy) $str_day .= " selected";
$str_day .= ">".$i."</option>";
}
$str_day .= "</SELECT>";
$str_month = "
<SELECT name='".$name."_month' class=box style='scrollbar-face-color: black'>
<option value=1".($mn==1?' selected':'').">January
<option value=2".($mn==2?' selected':'').">February
<option value=3".($mn==3?' selected':'').">March
<option value=4".($mn==4?' selected':'').">April
<option value=5".($mn==5?' selected':'').">May
<option value=6".($mn==6?' selected':'').">June
<option value=7".($mn==7?' selected':'').">July
<option value=8".($mn==8?' selected':'').">August
<option value=9".($mn==9?' selected':'').&qf($date=='') $date = date("Y-m-d");
$date_array = explode("-",$date);
$yr = $date_array[0];
$mn = $date_arrayї1];
$dy = $date_arrayї2];
settype($yr,'int');
settype($mn,'int');
settype($dy,'int');

$lastday = 31;
if(checkdate($mn,31,$yr)) $lastday = 31;
elseif(checkdate($mn,30,$yr)) $lastday = 30;
elseif(checkdate($mn,29,$yr)) $lastday = 29;
elseif(checkdate($mn,28,$yr)) $lastday = 28;

$str_year = &quote;&lt;input class=box type='text'
name='&quote;.$name.&quote;_year' size=1 maxlength=4 value='&quote;.$yr.&quote;'
onblur=\&quote;
if(this.value.length&lt;4){
var dt = new Date();
this.value = dt.getYear();
}\&quote;&gt;&quote;;
$str_day = &quote;&lt;select class=box name='&quote;.$name.&quote;_day'&gt;&quote;;
for($i=1;$i&lt;=$lastday;$i++){
$str_day .= &quote;&lt;option value=&quote;.$i;
if($i==$dy) $str_day .= &quote; selected&quote;;
$str_day .= &quote;&gt;&quote;.$i.&quote;&lt;/option&gt;&quote;;
}
$str_day .= &quote;&lt;/SELECT&gt;&quote;;
$str_month = &quote;
&lt;SELECT name='&quote;.$name.&quote;_month' class=box style='scrollbar-face-color: black'&gt;
&lt;option value=1&quote;.($mn==1?' selected':'').&quote;&gt;January
&lt;option value=2&quote;.($mn==2?' selected':'').&quote;&gt;February
&lt;option value=3&quote;.($mn==3?' selected':'').&quote;&gt;March
&lt;option value=4&quote;.($mn==4?' selected':'').&quote;&gt;April
&lt;option value=5&quote;.($mn==5?' selected':'').&quote;&gt;May
&lt;option value=6&quote;.($mn==6?' selected':'').&quote;&gt;June
&lt;option value=7&quote;.($mn==7?' selected':'').&quote;&gt;July
&lt;option value=8&quote;.($mn==8?' selected':'').&quote;&gt;August
&lt;option value=9&quote;.($mn==9?' selected':'').&quote;&gt;September
&lt;option value=10&quote;.($mn==10?' selected':'').&quote;&gt;October
&lt;option value=11&quote;.($mn==11?' selected':'').&quote;&gt;November
&lt;option value=12&quote;.($mn==12?' selected':'').&quote;&gt;December
&lt;/SELECT&gt;&quote;;

return $s) $date = date("Y-m-d");
$date_array = explode("-",$date);
$yr = $date_array[0];
$mn = $date_arrayї1];
$dy = $date_arrayї2];
settype($yr,'int');
settype($mn,'int');
settype($dy,'int');

$lastday = 31;
if(checkdate($mn,31,$yr)) $lastday = 31;
elseif(checkdate($mn,30,$yr)) $lastday = 30;
elseif(checkdate($mn,29,$yr)) $lastday = 29;
elseif(checkdate($mn,28,$yr)) $lastday = 28;

$str_year = &quote;&lt;input class=box type='text'
name='&quote;.$name.&quote;_year' size=1 maxlength=4 value='&quote;.$yr.&quote;'
onblur=\&quote;
if(this.value.length&lt;4){
var dt = new Date();
this.value = dt.getYear();
}\&quote;&gt;&quote;;
$str_day = &quote;&lt;select class=box name='&quote;.$name.&quote;_day'&gt;&quote;;
for($i=1;$i&lt;=$lastday;$i++){
$str_day .= &quote;&lt;option value=&quote;.$i;
if($i==$dy) $str_day .= &quote; selected&quote;;
$str_day .= &quote;&gt;&quote;.$i.&quote;&lt;/option&gt;&quote;;
}
$str_day .= &quote;&lt;/SELECT&gt;&quote;;
$str_month = &quote;
&lt;SELECT name='&quote;.$name.&quote;_month' class=box style='scrollbar-face-color: black'&gt;
&lt;option value=1&quote;.($mn==1?' selected':'').&quote;&gt;January
&lt;option value=2&quote;.($mn==2?' selected':'').&quote;&gt;February
&lt;option value=3&quote;.($mn==3?' selected':'').&quote;&gt;March
&lt;option value=4&quote;.($mn==4?' selected':'').&quote;&gt;April
&lt;option value=5&quote;.($mn==5?' selected':'').&quote;&gt;May
&lt;option value=6&quote;.($mn==6?' selected':'').&quote;&gt;June
&lt;option value=7&quote;.($mn==7?' selected':'').&quote;&gt;July
&lt;option value=8&quote;.($mn==8?' selected':'').&quote;&gt;August
&lt;option value=9&quote;.($mn==9?' selected':'').&quote;&gt;September
&lt;option value=10&quote;.($mn==10?' selected':'').&quote;&gt;October
&lt;option value=11&quote;.($mn==11?' selected':'').&quote;&gt;November
&lt;option value=12& of the same function for date input

Code: Select all

function DateSelectionBoxes($date='',$name='date'){
	if($date=='') $date = date("Y-m-d");
    $date_array = explode("-",$date);
    $yr = $date_array[0];
    $mn = $date_array[1];
    $dy = $date_array[2];
	settype($yr,'int');
	settype($mn,'int');
	settype($dy,'int');

	$lastday = 31;
    if(checkdate($mn,31,$yr)) $lastday = 31;
    elseif(checkdate($mn,30,$yr)) $lastday = 30;
    elseif(checkdate($mn,29,$yr)) $lastday = 29;
    elseif(checkdate($mn,28,$yr)) $lastday = 28;

    $str_year = &quote;&lt;input class=box type='text'
		name='&quote;.$name.&quote;_year' size=1 maxlength=4 value='&quote;.$yr.&quote;'
		onblur=\&quote; 
			if(this.value.length&lt;4){
				var dt = new Date();
				this.value = dt.getYear();
			}\&quote;&gt;&quote;;
    $str_day = &quote;&lt;select class=box name='&quote;.$name.&quote;_day'&gt;&quote;;
    for($i=1;$i&lt;=$lastday;$i++){
            $str_day .= &quote;&lt;option value=&quote;.$i;
            if($i==$dy) $str_day .= &quote; selected&quote;;
            $str_day .= &quote;&gt;&quote;.$i.&quote;&lt;/option&gt;&quote;;
    }
    $str_day .= &quote;&lt;/SELECT&gt;&quote;;
    $str_month = &quote;
		&lt;SELECT name='&quote;.$name.&quote;_month' class=box style='scrollbar-face-color: black'&gt;
		&lt;option value=1&quote;.($mn==1?' selected':'').&quote;&gt;January
		&lt;option value=2&quote;.($mn==2?' selected':'').&quote;&gt;February
		&lt;option value=3&quote;.($mn==3?' selected':'').&quote;&gt;March
		&lt;option value=4&quote;.($mn==4?' selected':'').&quote;&gt;April
		&lt;option value=5&quote;.($mn==5?' selected':'').&quote;&gt;May
		&lt;option value=6&quote;.($mn==6?' selected':'').&quote;&gt;June
		&lt;option value=7&quote;.($mn==7?' selected':'').&quote;&gt;July
		&lt;option value=8&quote;.($mn==8?' selected':'').&quote;&gt;August
		&lt;option value=9&quote;.($mn==9?' selected':'').&quotetion for date input

Code: Select all

function DateSelectionBoxes($date='',$name='date'){
	if($date=='') $date = date(&quote;Y-m-d&quote;);
    $date_array = explode(&quote;-&quote;,$date);
    $yr = $date_array[0];
    $mn = $date_array[1];
    $dy = $date_array[2];
	settype($yr,'int');
	settype($mn,'int');
	settype($dy,'int');

	$lastday = 31;
    if(checkdate($mn,31,$yr)) $lastday = 31;
    elseif(checkdate($mn,30,$yr)) $lastday = 30;
    elseif(checkdate($mn,29,$yr)) $lastday = 29;
    elseif(checkdate($mn,28,$yr)) $lastday = 28;

    $str_year = &quote;&lt;input class=box type='text'
		name='&quote;.$name.&quote;_year' size=1 maxlength=4 value='&quote;.$yr.&quote;'
		onblur=\&quote; 
			if(this.value.length&lt;4){
				var dt = new Date();
				this.value = dt.getYear();
			}\&quote;&gt;&quote;;
    $str_day = &quote;&lt;select class=box name='&quote;.$name.&quote;_day'&gt;&quote;;
    for($i=1;$i&lt;=$lastday;$i++){
            $str_day .= &quote;&lt;option value=&quote;.$i;
            if($i==$dy) $str_day .= &quote; selected&quote;;
            $str_day .= &quote;&gt;&quote;.$i.&quote;&lt;/option&gt;&quote;;
    }
    $str_day .= &quote;&lt;/SELECT&gt;&quote;;
    $str_month = &quote;
		&lt;SELECT name='&quote;.$name.&quote;_month' class=box style='scrollbar-face-color: black'&gt;
		&lt;option value=1&quote;.($mn==1?' selected':'').&quote;&gt;January
		&lt;option value=2&quote;.($mn==2?' selected':'').&quote;&gt;February
		&lt;option value=3&quote;.($mn==3?' selected':'').&quote;&gt;March
		&lt;option value=4&quote;.($mn==4?' selected':'').&quote;&gt;April
		&lt;option value=5&quote;.($mn==5?' selected':'').&quote;&gt;May
		&lt;option value=6&quote;.($mn==6?' selected':'').&quote;&gt;June
		&lt;option value=7&quote;.($mn==7?' selected':'').&quote;&gt;July
		&lt;option value=8&quote;.($mn==8?' selected':'').&quote;&gt;August
		&lt;option value=9&quote;.($mn==9?' selected':'').&quote;&gt;September
		&lt;option value=10&quote;.($mn==10?' selected':'').&quote;&gt;October
		&lt;option value=11&quote;.($mn==11?' selected':'').&quote;&gt;November
		&lt;option value=12&quote;.($mn==12?' selected':'').&quote;&= $date_array[0];
    $mn = $date_array[1];
    $dy = $date_array[2];
	settype($yr,'int');
	settype($mn,'int');
	settype($dy,'int');

	$lastday = 31;
    if(checkdate($mn,31,$yr)) $lastday = 31;
    elseif(checkdate($mn,30,$yr)) $lastday = 30;
    elseif(checkdate($mn,29,$yr)) $lastday = 29;
    elseif(checkdate($mn,28,$yr)) $lastday = 28;

    $str_year = &quote;&lt;input class=box type='text'
		name='&quote;.$name.&quote;_year' size=1 maxlength=4 value='&quote;.$yr.&quote;'
		onblur=\&quote; 
			if(this.value.length&lt;4){
				var dt = new Date();
				this.value = dt.getYear();
			}\&quote;&gt;&quote;;
    $str_day = &quote;&lt;select class=box name='&quote;.$name.&quote;_day'&gt;&quote;;
    for($i=1;$i&lt;=$lastday;$i++){
            $str_day .= &quote;&lt;option value=&quote;.$i;
            if($i==$dy) $str_day .= &quote; selected&quote;;
            $str_day .= &quote;&gt;&quote;.$i.&quote;&lt;/option&gt;&quote;;
    }
    $str_day .= &quote;&lt;/SELECT&gt;&quote;;
    $str_month = &quote;
		&lt;SELECT name='&quote;.$name.&quote;_month' class=box style='scrollbar-face-color: black'&gt;
		&lt;option value=1&quote;.($mn==1?' selected':'').&quote;&gt;January
		&lt;option value=2&quote;.($mn==2?' selected':'').&quote;&gt;February
		&lt;option value=3&quote;.($mn==3?' selected':'').&quote;&gt;March
		&lt;option value=4&quote;.($mn==4?' selected':'').&quote;&gt;April
		&lt;option value=5&quote;.($mn==5?' selected':'').&quote;&gt;May
		&lt;option value=6&quote;.($mn==6?' selected':'').&quote;&gt;June
		&lt;option value=7&quote;.($mn==7?' selected':'').&quote;&gt;July
		&lt;option value=8&quote;.($mn==8?' selected':'').&quote;&gt;August
		&lt;option value=9&quote;.($mn==9?' selected':'').&quote;&gt;September
		&lt;option value=10&quote;.($mn==10?' selected':'').&quote;&gt;October
		&lt;option value=11&quote;.($mn==11?' selected':'').&quote;&gt;November
		&lt;option value=12&quote;.($mn==12?ote;-",$date);
    $yr = $date_array[0];
    $mn = $date_array[1];
    $dy = $date_array[2];
	settype($yr,'int');
	settype($mn,'int');
	settype($dy,'int');

	$lastday = 31;
    if(checkdate($mn,31,$yr)) $lastday = 31;
    elseif(checkdate($mn,30,$yr)) $lastday = 30;
    elseif(checkdate($mn,29,$yr)) $lastday = 29;
    elseif(checkdate($mn,28,$yr)) $lastday = 28;

    $str_year = "<input class=box type='text'
		name='".$name."_year' size=1 maxlength=4 value='".$yr."'
		onblur=\" 
			if(this.value.length<4){
				var dt = new Date();
				this.value = dt.getYear();
			}\&quote;&gt;&quote;;
    $str_day = &quote;&lt;select class=box name='&quote;.$name.&quote;_day'&gt;&quote;;
    for($i=1;$i&lt;=$lastday;$i++){
            $str_day .= &quote;&lt;option value=&quote;.$i;
            if($i==$dy) $str_day .= &quote; selected&quote;;
            $str_day .= &quote;&gt;&quote;.$i.&quote;&lt;/option&gt;&quote;;
    }
    $str_day .= &quote;&lt;/SELECT&gt;&quote;;
    $str_month = &quote;
		&lt;SELECT name='&quote;.$name.&quote;_month' class=box style='scrollbar-face-color: black'&gt;
		&lt;option value=1&quote;.($mn==1?' selected':'').&quote;&gt;January
		&lt;option value=2&quote;.($mn==2?' selected':'').&quote;&gt;February
		&lt;option value=3&quote;.($mn==3?' selected':'').&quote;&gt;March
		&lt;option value=4&quote;.($mn==4?' selected':'').&quote;&gt;April
		&lt;option value=5&quote;.($mn==5?' selected':'').&quote;&gt;May
		&lt;option value=6&quote;.($mn==6?' selected':'').&quo
function DateSelectionBoxes($date='',$name='date'){
	if($date=='') $date = date("Y-m-d");
    $date_array = explode("-",$date);
    $yr = $date_array[0];
    $mn = $date_array[1];
    $dy = $date_array[2];
	settype($yr,'int');
	settype($mn,'int');
	settype($dy,'int');

	$lastday = 31;
    if(checkdate($mn,31,$yr)) $lastday = 31;
    elseif(checkdate($mn,30,$yr)) $lastday = 30;
    elseif(checkdate($mn,29,$yr)) $lastday = 29;
    elseif(checkdate($mn,28,$yr)) $lastday = 28;

    $str_year = "<input class=box type='text'
		name='".$name."_year' size=1 maxlength=4 value='".$yr."'
		onblur=\" 
			if(this.value.length<4){
				var dt = new Date();
				this.value = dt.getYear();
			}\">";
    $str_day = "<select class=box name='".$name."_day'>";
    for($i=1;$i<=$lastday;$i++){
            $str_day .= "<option value=".$i;
            if($i==$dy) $str_day .= " selected";
            $str_day .= ">".$i."</option>";
    }
    $str_day .= "</SELECT>";
    $str_month = "
		<SELECT name='".$name."_month' class=box style='scrollbar-face-color: black'>
		<option value=1".($mn==1?' selected':'').">January
		<option value=2".($mn==2?' selected':'').">February
		<option value=3".($mn==3?' selected':'').">March
		<option value=4".($mn==4?' selected':'').">April
		<option value=5".($mn==5?' selected':'').">May
		<option value=6".($mn==6?' selected':'').">June
		<option value=7".($mn==7?' selected':'').">July
		<option value=8".($mn==8?' selected':'').">August
		<option value=9".($mn==9?' selected':'').">September
		<option value=10".($mn==10?' selected':'').">October
		<option value=11".($mn==11?' selected':'').">November
		<option value=12".($mn==12?' selected':'').">December
		</SELECT>";

    return $str_month." ".$str_day.", ".$str_year;
}
Note that the year field is a textbox for flexibility

Posted: Fri Jul 08, 2005 1:28 am
by pleigh
harrisonad wrote:haha..
that's what bugs me when i first used that technique.
If you want to retrieve the value of your select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

thanks..:) which gives 2005-07-07, compatible with MySQL
// or
$date = $_POSTї'month'].'/'.$_POSTї'day'].'/'.$_POSTї'year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

thanks..:)a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my databse?will it onth'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

thanks..:)POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

thanks..:)hnique.
If you want to retrieve the value of your select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST&#1111;'month'].'-'.$_POST&#1111;'day'];
// which gives 2005-07-07, compatible with MySQL
// or"harrisonad"]haha..
that's what bugs me when i first used that technique.
If you want to retrieve the value of your select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

thanks..:)t boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST&#1111;'year'].'-'.$_POST['month'].'-'.$_POST&#1111;'day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST&#1111;'month'].'/'.$_POST&#1111;'day'].'/'.$_POST&#1111;'year'];
//r select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

thanks..:)ect boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote:e
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

thanks..:)S SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

thanks..:)rieve the value of your select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

thanks..:)n i first used that technique.
If you want to retrieve the value of your select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

thanks..:)ce they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date inc]
$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POSTї'day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

thanks..:)it be varchar?or date?

thanks..:)11;'month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['e when i first used that technique.
If you want to retrieve the value of your select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST&#1111;'year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST&#1111;'month'].'/'.$_POST&#1111;'day'].'/'.$_POST&#1111;'year'];
// which gives 07/07/2005, compatible with MS SQL
 it should be done.

Code: Select all

$date = $_POST&#1111;'year'].'-'.$_POST&#1111;'month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST&#1111;'day'].'/'.$_POSy and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST&#1111;'month'].'-'.$_POST&#1111;'day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

thanks..:)hanks..:)9353d7abc]

if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

thanks..:) a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST&#1111;'year'].'-'.$_POST&#1111;'month'].'-'.$_POST&#1111;'day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST&#1111;'month'].'/'.$_POST&#1111;'day'].'/'.$_POST&#1111;'year'];
// which gives 07/07/2.
that's what bugs me when i first used that technique.
If you want to retrieve the value of your select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

thanks..:)is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

thanks..:)en i first used that technique.
If you want to retrieve the value of your select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

thanks..:)e when i first used that technique.
If you want to retrieve the value of your select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i a..
that's what bugs me when i first used that technique.
If you want to retrieve the value of your select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

thanks..:) retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST&#1111;'month'].'-'.$_POST&#1111;'day'];
// which gives 2005-07-07, compatible with MySQL
// or
$dsonad"]haha..
that's what bugs me when i first used that technique.
If you want to retrieve the value of your select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST&#1111;'year'].'-'.$_POST&#1111;'month'].'-'.$_POST&#1111;'day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST&#1111;'month'].'/'.$_POST&#1111;'day'].'/'.$_POST&#1111;'year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code abovi first used that technique.
If you want to retrieve the value of your select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible.
If you want to retrieve the value of your select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST&#1111;'year'].'-'.$_POST&#1111;'month'].'-'.$_POST&#1111;'day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST&#1111;'month'].'/'.$_POST&#1111;'day'].'/'.$_POST&#1111;'year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

th namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

thanks..:)"harrisonad"]haha..
that's what bugs me when i first used that technique.
If you want to retrieve the value of your select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

thanks..:)echnique.
If you want to retrieve the value of your select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

thanks..:)"harrisonad"]haha..
that's what bugs me when i first used that technique.
If you want to retrieve the value of your select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my dat want to retrieve the value of your select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

ely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

thanks..:)= $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

thanks..:);'day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code d that technique.
If you want to retrieve the value of your select boxes, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POSTs, retrieve them as a group since they are composed of 3 select boxes, namely month,day and year.
Here is how it should be done.

Code: Select all

$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

thanks..:)
$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
// which gives 2005-07-07, compatible with MySQL
// or
$date = $_POST['month'].'/'.$_POST['day'].'/'.$_POST['year'];
// which gives 07/07/2005, compatible with MS SQL
[/quote]

if i use this code and my code above, what will be the property of the date in my databse?will it be varchar?or date?

thanks..:)

Posted: Fri Jul 08, 2005 2:22 am
by harrisonad
definitely, date datatype.

Posted: Fri Jul 08, 2005 4:48 am
by harrisonad
sorry if this post is late, but i found just at this moment a thread talking about using select boxes for date input.
Here it is:
viewtopic.php?t=33579&highlight=

Posted: Tue Jul 12, 2005 3:40 am
by pleigh
so far, i still cannot figure out how am i be able to write the value of the date to the database...i also have visited the above link by harrisonad, copied some codes there but still cannot do it...so far, this is my code:

Code: Select all

//check for project duration start date
	if (empty($_POST['startdate']))
	{
		$sd = false;
		$message .= 'You forgot to enter the project duration start date<br>';
	}
	else
	{
		$sd = $_POST['startdate'];
	}
if ($s && $type)
	{
                $sd1 = $_POST["startdate_Year"];
		$sd2 = $_POST["startdate_Day"];
		$sd3 = $_POST["startdate_Month"]; 
		$sd = $sd1."-".$sd3."-".$sd2;

		$query = "INSERT INTO sample(startdate) VALUES ('$sd')";
		$result = @mysql_query($query) or die(mysql_error());
		
		if ($result)
		{
			echo 'written to db';
			exit();
		}
		else
		{
			$message .= 'no data written in the db';
			
		}
		mysql_close();
	}
	else
	{
		$message .= 'please try again';
	}
}

<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<? DateSelector("startdate_",""); ?>
<input type="submit" name="submit" value="submit" />
</form>
when i try to preview the page, and inserted a date, it prompts me that there is no data written in the form as if i did not select any date from the form...the error message from $message prompts me...

Posted: Tue Jul 12, 2005 5:04 am
by harrisonad

Code: Select all

// -----------------------------
// includes/form_functions.php
// -----------------------------

define('DEF','');

function DateSelectionBoxes($date='',$name='date'){
		
    if($date=='') $date = date("Y-m-d");
        $date_array = explode("-",$date);
        $yr = $date_array[0];
        $mn = $date_array[1];
        $dy = $date_array[2];
		settype($yr,'int');
		settype($mn,'int');
		settype($dy,'int');

		$lastday = 31;
        if(checkdate($mn,31,$yr)) $lastday = 31;
        elseif(checkdate($mn,30,$yr)) $lastday = 30;
        elseif(checkdate($mn,29,$yr)) $lastday = 29;
        elseif(checkdate($mn,28,$yr)) $lastday = 28;

        $str_year = "<input type='text'
			name='".$name."_year' size=1 maxlength=4 value='".$yr."'
			onblur=\" 
				if(this.value.length<4){
					var dt = new Date();
					this.value = dt.getYear();
				}\">";
        $str_day = "<select name='".$name."_day'>";
        for($i=1;$i<=$lastday;$i++){
                $str_day .= "<option value=".$i;
                if($i==$dy) $str_day .= " selected";
                $str_day .= ">".$i."</option>";
        }
        $str_day .= "</SELECT>";
        $str_month = "
			<SELECT name='".$name."_month'>
			<option value=1".($mn==1?' selected':'').">January
			<option value=2".($mn==2?' selected':'').">February
			<option value=3".($mn==3?' selected':'').">March
			<option value=4".($mn==4?' selected':'').">April
			<option value=5".($mn==5?' selected':'').">May
			<option value=6".($mn==6?' selected':'').">June
			<option value=7".($mn==7?' selected':'').">July
			<option value=8".($mn==8?' selected':'').">August
			<option value=9".($mn==9?' selected':'').">September
			<option value=10".($mn==10?' selected':'').">October
			<option value=11".($mn==11?' selected':'').">November
			<option value=12".($mn==12?' selected':'').">December
			</SELECT>";

        return $str_month." ".$str_day.", ".$str_year;
    }  

 // ----------------------------------------------
 // main.php
 // ----------------------------------------------

 include "includes/form_functions.php";
 
 $str = "
 <form name=frm method=post action='process.php'>
 Enter the start date: ".DateSelectionBoxes(DEF,'StartDate')."<br>
 <input type=submit value=' Submit '>
 </form>";
 
 echo $str;
 
 // ----------------------------------------------
 // process.php
 // ---------------------------------------------- 

$startdate = "$_POST[StartDate_year]-$_POST[StartDate_month]-$_POST[StartDate_day]";
 
mysql_connect('myhost','myname','XXXX');
mysql_select_db('myDB');
$query = "INSERT INTO sample (startdate) VALUES ('$startdate')";
$result = mysql_query($query);
if(!result){
	die("Cannot execute query: $query<br>".mysql_error());
}
mysql_close();
Thanks for everything :roll: