MySQL datetime INSERT/UPDATE reverts to 0000-00-00 00:00:00
Posted: Wed Nov 15, 2006 10:53 am
I'm using 3 form fields to get my date and time criteria (the hourmin function below creates two select list menus for hour and minute values):
Then, during the submission process, I build my datetime variable like so (the dateconvert function just takes the MM/DD/YYYY formulated submission and switches it around to MySQL's preferred YYYY/MM/DD):
and insert into DB like so:
I searched this forum, and found mentions of making sure to include the quotation marks, otherwise MySQL treats the "date" portion of the insert as math, which is why I tried formulating it the way it is above. I have also tried it without the quotation marks, to no avail. I'm sure it's something simple I'm missing. I'm not an experienced PHP/MySQL programmer.
When I submit the form and INSERT into MySQL, it accepts everything from the form, but alway inserts the MySQL default 0000-00-00 00:00:00 as the date. When I test submit this and just echo the variables to a browser window, the $timedate value comes through as:
'2006-11-14' 08:00:00
Is that not how MySQL wants it to look when it comes in? Any help is greatly appreciated.
max
Code: Select all
<form name="editrelease" id="editrelease" method="post" action="<?php echo $PHP_SELF;?>?editreleasesubmit=1"-->
<!--form name="editrelease" id="editrelease" method="post" action="phpAdminNewsSubmit.php?editreleasesubmit=1"-->
<?php if ($edit){ ?>
<input type="hidden" name="releaseid" value="<?php echo $id; ?>">
<?php } ?>
<table width="100%" id="tables">
<tr>
<td align="left" valign="top" style="margin-top:4px;">Publish Date/Time:</td><td> <input type="text" name="date"<?php if($edit){ echo " value=$outputdate"; }?> size=10><a href="javascript:popCal('date','editrelease')"><img src="bbnadmin/images/calendar.gif" border="0" valign="absmiddle"></a> Time: <?php hourmin($hid = "hour", $mid = "minute", $hval = "$outputhour", $mval = "$outputmin"); ?><br />
<span class="smallcopy">MM/DD/YYYY | Time selection based on 24-hour clock, EST</span>
</td>
</tr>Code: Select all
$date = $_POST['date'];
$time = $_POST['hour'] . ":" . $_POST['minute'] . ":00";
$date = dateconvert($date, 1);
$timedate = "'$date'" . " " . $time;Code: Select all
$query="INSERT INTO newsreleases (headline,subhead,bodycopy,aboutbbn,date) VALUES ('$headline','$subhead','$bodycopy','$aboutbbn','$timedate')";When I submit the form and INSERT into MySQL, it accepts everything from the form, but alway inserts the MySQL default 0000-00-00 00:00:00 as the date. When I test submit this and just echo the variables to a browser window, the $timedate value comes through as:
'2006-11-14' 08:00:00
Is that not how MySQL wants it to look when it comes in? Any help is greatly appreciated.
max