Jump to content

Insert Date into mySQL from drop down menus


mikemcg36

Recommended Posts

I am trying to insert a date into a mySQL table from html drop downs with php. Right now when I enter the date it goes into the database as 0000-00-00. Can anybody see why it might be doing this?

 

My html:

<label for='birthdate' >Birthdate (Optional):</label><br/>
    <select name='month' id='month' value='<?php echo $fgmembersite->SafeDisplay('month') ?>'>
<option value="01" selected="January">January</option>
<option value="02">February</option>
<option value="03">March</option>
        etc...
    </select>  
    <select name='day' id='day' value='<?php echo $fgmembersite->SafeDisplay('day') ?>'>
<option value="01" selected="1">1</option>
<option value="02">2</option>
<option value="03">3</option>
etc...
    </select>  
    <select name='year' id='year' value='<?php echo $fgmembersite->SafeDisplay('year') ?>'>
<option value="2010" selected="2010">2010</option>
<option value="2009">2009</option>
<option value="2008">2008</option>
etc...
    </select>

 

And my php to collect info:

$formvars['birthdate'] = $this->Sanitize($_POST['year'], $_POST['month'], $_POST['day']);

php where I make table:

"birthdate DATE NOT NULL ,".

 

php to insert into mysql:

$insert_query = 'insert into '.$this->tablename.'(
                name,
	address,
	birthdate,
	sex,
	program,
	guide,
                email,
                username,
                password,
                confirmcode
                )
                values
                (
                "' . $this->SanitizeForSQL($formvars['name']) . '",
	"' . $this->SanitizeForSQL($formvars['address']) . '",
	"' . $this->SanitizeForSQL($formvars['birthdate']) . '",
	"' . $this->SanitizeForSQL($formvars['sex']) . '",
	"' . $this->SanitizeForSQL($formvars['program']) . '",
	"' . $this->SanitizeForSQL($formvars['guide']) . '",
                "' . $this->SanitizeForSQL($formvars['email']) . '",
                "' . $this->SanitizeForSQL($formvars['username']) . '",
                "' . md5($formvars['password']) . '",
                "' . $confirmcode . '"
                )';  

 

Thank you!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.