Can't figure out what's wrong with my date formatting. I''m not sure if it has to do with the "trim" on the $_POST, or in the string conversion to make it MySQL formatted, or within the form section where the dates are being selected.
In the database, it's rendering as a blank date: 0000-00-00.
Just to condense my script, here are the areas that are relevant to the date:
$bmonth = $_POST['bmonth'];
$bday = trim($_POST['bday']);
$byear = trim($_POST['byear']);
//CONVERT BIRTHDATE TO MYSQL FORMAT
$birth_date = "$byear."-".$bmonth."-".$bday";
$birth_date = mysql_real_escape_string($_POST['birth_date']);
$sql = mysql_query("INSERT INTO member_profile (firstname, lastname, birth_date, email, username, password, country, sign_up_date, gender)
VALUES('$firstname', '$lastname', '$birth_date', '$email', '$username', '$db_password', '$country', now(), '$gender')")
or die (mysql_error());
And here's the form section to select the birthdate:
<tr class="formDetails"><p class="eventform">
<td class="formField" align="left"><label for="bmonth">Birthdate:</label></td>
<td class="formDetails" align="left"><select name="bmonth" id="bmonth">
<?php
$months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
for ($i = 1; $i <= 12; $i++) {?>
<option value="<?php echo $i < 10 ? '0'.$i : $i; ?>"
<?php if(isset($_POST['bmonth']) && $_POST['bmonth'] == $i) print 'selected'; ?>>
<?php echo $months[$i-1]; ?>
<?php } ?>
</select>
<label for="bday">Day:</label>
<select id="bday" name="bday">
<?php
for ($x=1; $x<=31; $x++){ ?>
<option value="<?php echo $x < 10 ? '0'.$x : $x ;?>">
<?php echo $x < 10 ? '0'.$x : $x ;?>
</option>
<?php } ?>
</select>
<label for="byear">Year:</label>
<select id="byear" name="byear">
<?php
$thisYear = date('Y');
for ($x = $thisYear - 70; $x <= $thisYear -13; $x++){ ?>
<option value="<?php echo $x ;?>">
<?php echo $x ;?>
</option>
<?php } ?>
</select>
<img src="images/notice-note2.png" border="0" width="15" height="15" alt='* This Field is required' title='This Field is Required' />
</td></p>
</tr>