I have an editable form, that (upon other things) retrieves a date from mysql. To prepopulate this text field, I use:
$result = mysql_query("SELECT DATE_FORMAT(Expiration_Date, '%d-%b-%y') AS DateX FROM MyTable) or exit(mysql_error());
Which will return (for example): 01-Jan-06
I have a dropdown field that a user can use to select the number of days to add to this date. In addition, however, the user should also be allowed to opt to not use the dropdown, but type in the value instead, in the d-M-y format.
So, to continue the code...
while ($row = mysql_fetch_assoc($result)) {
$expdate = $row['DateX'];
echo "<td><input type=\"text\" name=\"expdate\" value=\"$expdate\"></td>
<td valign=\"top\"><b>Add days:</b>
<select name=\"adddays\" class=\"selects\">";
for ($day=0; $day<=31; $day++) {
echo "<option value=\"$day\">$day</option>\n";
}
echo "</select>";
So, I want to add the expdate and the adddays fields and enter that into mysql, formatting as yyyy-mm-dd hh-mm-ss.
This is what I've tried, but it's not working:
if (!empty($_POST['expdate'])) {
$xdate1 = date("Y-m-d H:i:s", $_POST['expdate']);
$xdate2 = strtotime("+".$adddays." days", $xdate1);
} else {
$arrErrors['expdate'] = 'Please set the expiration date.';
}
All this does is return (for example) 88406. Can someone help?