I am collecting the date in a form with individual month, day, year fields and then forming a string (YYYY/MM/DD) to submit to MySQL. It is very common for a user to know an appropriate year to enter, but unable to enter the day and/or month. In this circumstance the year value when submitted is lost because the 2006/00/00 is an invalid date. Is it possible to save the year in DB (datatype=date) without using separate new field? I really dont want to display a default month/day either. Any ideas? Here's my code:
$form = 'Y';
if(isset($_POST['continue'])) {
$message = NULL;
if(empty($_POST['f_name'])) {
$f_name = FALSE;
$message .= '<p>Please enter a First Name.</p>';
} else {
$f_name = $_POST['f_name'];
}
if(empty($_POST['l_name'])) {
$l_name = FALSE;
$message .= '<p>Please enter a Last Name.</p>';
} else {
$l_name = $_POST['l_name'];
}
if(empty($_POST['d_name'])) {
$d_name = FALSE;
$message .= '<p>Please enter a Display Name.</p>';
} else {
$d_name = $_POST['d_name'];
}
$birth_date = "{$_POST['birth_year']}/{$_POST['birth_month']}/{$_POST['birth_day']}"; //FORMATTING THE DATE
$death_date = "{$_POST['death_year']}/{$_POST['death_month']}/{$_POST['death_day']}"; //FORMATTING THE DATE
$home_city = $_POST['home_city'];
$home_state = $_POST['home_state'];
$creator_id = $_SESSION['fun_id'];
if ($f_name && $l_name && d_name) {
require_once ('x/mysql_connect.php');
$query = "INSERT INTO obituary (
creator_id,
creator_type,
created,
first_name,
last_name,
display_name,
birth_date,
death_date,
home_city,
home_state)
VALUES (
'$creator_id',
'A',
NOW(),
'$f_name',
'$l_name',
'$d_name',
'$birth_date',
'$death_date',
'$home_city',
'$home_state')";
$result = @mysql_query($query);
if ($result) {
$query1 = "SELECT obit_id FROM obituary ORDER BY obit_id DESC LIMIT 1";
$result1 = @mysql_query($query1);
$row1 = mysql_fetch_array($result1, MYSQL_NUM);
$obit_id = $row1[0];
$form = 'N';
} else {
echo mysql_error();
}
}
}