Click here to Skip to main content
16,012,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how i can post this date of birth function value to my database through my registration page? Please help !! Any other suggestions, i need three drop down in my php form.

XML
<?
function date_dropdown($year_limit = 0){
        $html_output = '    <div id="date_select" >'."\n";
        $html_output .= '        <label for="date_day"></label>'."\n";

        /*days*/
        $html_output .= '           <select name="date_day" id="day_select">'."\n";
            for ($day = 1; $day <= 31; $day++) {
                $html_output .= '               <option>' . $day . '</option>'."\n";
            }
        $html_output .= '           </select>'."\n";

        /*months*/
        $html_output .= '           <select name="date_month" id="month_select" >'."\n";
        $months = array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
            for ($month = 1; $month <= 12; $month++) {
                $html_output .= '               <option value="' . $month . '">' . $months[$month] . '</option>'."\n";
            }
        $html_output .= '           </select>'."\n";

        /*years*/
        $html_output .= '           <select name="date_year" id="year_select">'."\n";
            for ($year = 1900; $year <= (date("Y") - $year_limit); $year++) {
                $html_output .= '               <option>' . $year . '</option>'."\n";
            }
        $html_output .= '           </select>'."\n";

        $html_output .= '   </div>'."\n";
    return $html_output;
}


?>


html form code:
 <td>			// or add date of birth age condition in ()
							 echo date_dropdown();
							 		?>
			</td>
Posted
Updated 4-Apr-12 4:31am
v4
Comments
Peta2010 30-Mar-12 14:01pm    
This is date of birth function for registration page. How i can add its selected value to database ?

In your action page ;
first get date of birth variables.depending on your method $_GET['date_year'] or $_POST['date_year'] etc.Then call mysql_real_escape_string to make them safe for database.($safeYear=mysql_real_escape_string($_GET['date_year']).
Then depending on your database schema call
mysql_query ("insert into youtTable values(....,'$safeDay.$safeMonth.$safeYear',....);
This is the simplest case .If your table has dateTime field than you should pass birth day after formatting obviosuly.By the way I'm assuming you are using your supplied code inside
<form>...</form>
block.

(Sorry for this barbarian answer at 2.00 a.m.)
 
Share this answer
 
v2
Comments
Peta2010 5-Apr-12 2:42am    
Can you please tell what i need write according my above mentioned code.
I used three drop downs in the html form and then pass all drop down values in variables and then in php i use cancatenation to make all three values together.

Its working.

$dob = $_POST['day'] . '-' . $_POST['month'] . '-' . $_POST['year'];
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900