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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.