can't store date in db

They have: 164 posts

Joined: Nov 2001

i have a function written like this..

<?php
function DOB_select($date=\"\")
{
   
$day=substr($date,8,2);   
   
$month=substr($date,5,2);
   
$year=substr($date,0,4);
   
   
$date1 = \"<select name=\\"day\\">\";
   
$date1 .= \"<option></option>\";
    for (
$i=1; $i<32; $i++)
    {
        if (strlen(
$i) == 1)
           
$j = \"0\".$i;
        else
           
$j = $i;

       
$date1 .= \"<option value=$j \";
        if (
$day == $j)
           
$date1 .= \"selected\";
       
$date1 .= \">$j</option>\";
    }
   
   
$date1 .= \"</select>&nbsp;\";

   
$date2 = \"<select name=\\"month\\">\";
   
$date2 .= \"<option></option>\";
    for (
$g=1;$g<13;$g++)
    {
        if (strlen(
$g) == 1)
           
$f = \"0\".$g;
        else
           
$f = $g;
       
       
$date2 .= \"<option value=$f \";
        if (
$month == $f)
           
$date2 .= \"selected\";
       
$date2 .= \">$f</option>\";
    }
   
   
$date2 .= \"</select>&nbsp;\";

   
$date3 = \"<select name=\\"year\\">\";
   
$date3 .= \"<option></option>\";
    for (
$i=1900;$i<2002;$i++)
    {
       
$date3 .= \"<option value=$i \";
        if (
$year == $i)
           
$date3 .= \"selected\";
       
$date3 .= \">$i</option>\";
    }
       
   
$date3 .= \"</select>&nbsp;\";

$date = $date3.$date2.$date1;

return (
$date);
}
?>

i can't seems to get the value for the year, month and day. i do it this way because i add an extra field in a script tat i downloaded and it has to be this way in order to display all the select box.

anyidea how i should get the values?? my field in db are date.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

I tested your code. It works fine for me....
PHP file, PHPS file

The only modification I had to make, was add the year 2002 (made it print 1900-2005). It wasn't printing 2002 in the dropdown, so it couldn't be selected.

Mark Hensler
If there is no answer on Google, then there is no question.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.