【发布时间】:2014-10-19 05:34:03
【问题描述】:
我在输入字段中有一个文本的月、日和年,我想将其转换为稍后将插入到 MySQL 表中的“日期”字段中的日期。
来自 HTML 输入字段的文本月、日和年:“2014 年 8 月 25 日”。
PHP:
$time_cell_row = 1;
$time_cell_column = 1;
echo "<form name='timesubmit" . $time_cell_row . "' action='enter_time.php?action=timesubmit" .$time_cell_row . "' method='post'>";
$todays_date = strtotime("today"); //
$FormattedCurrDate = date('M d, Y', $todays_date); // Converts to "Aug 25, 2014"
echo "<th><input name=daycell1 type=text value=" . $FormattedCurrDate . "<disabled /></th>";
// The above echo statement displays "Aug" in a table cell instead of "Aug 25, 2014"
echo "<td><input name=submit_time" . $time_cell_row . $time_cell_column . " type=submit></input></td>";
echo "</form></tr>";
$date1 = $_POST['daycell1']; // null
echo "Date from input field: " . $date1; // Nothing is displayed from $date1 since is null
echo "<br>";
为什么 $_POST['daycell1'] 显示为 null 而不是输入“2014 年 8 月 25 日”?
【问题讨论】:
-
考虑表中特定列的数据类型
-
仅供参考:
<input>标签是无效标签,因此它们没有</结束标签,请改用value="your php variable" -
echo "<th><input name=daycell1 type=text value=" . $FormattedCurrDate . "<disabled /></th>";不要使用disabled属性,使用readonly并删除多余的< -
放置变量 '$FormattedCurrDate' 并将 'disabled' 更改为 'readonly' 使其工作!现在下一部分是如何将此字符串“2014 年 8 月 25 日”转换为日期,以便将其插入 MySQL 表中?