mikemcg36 Posted March 22, 2012 Share Posted March 22, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/259471-insert-date-into-mysql-from-drop-down-menus/ Share on other sites More sharing options...
DataSpy Posted March 22, 2012 Share Posted March 22, 2012 echo back birthday to see what you get before you enter it into the database, it looks like it would come out as 0000, 00, 00 instead of 0000-00-00 Quote Link to comment https://forums.phpfreaks.com/topic/259471-insert-date-into-mysql-from-drop-down-menus/#findComment-1330092 Share on other sites More sharing options...
mikemcg36 Posted March 22, 2012 Author Share Posted March 22, 2012 Sorry, can you explain the easiest way to echo the date input? Quote Link to comment https://forums.phpfreaks.com/topic/259471-insert-date-into-mysql-from-drop-down-menus/#findComment-1330179 Share on other sites More sharing options...
mikemcg36 Posted March 22, 2012 Author Share Posted March 22, 2012 Figured it out! It was a problem with the way I concatenated the date, I used this format and it worked. $date = $year ."-". $month ."-". $day; Quote Link to comment https://forums.phpfreaks.com/topic/259471-insert-date-into-mysql-from-drop-down-menus/#findComment-1330185 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.