此代码是一个html代表表单上的日期选择器控件,我想获取该值以便将其插入到Mysql DB中,即时通讯使用Php
我尝试过类似的东西: $ _POST [我不知道这里要包括什么]
提前致谢
<li class="form-line form-line-column" id="id_10">
<label class="form-label-top" id="label_10" for="input_10"> National ID :<span class="form-required">*</span> </label>
<div id="div" class="form-input-wide"><span class="form-sub-label-container">
<input class="form-textbox validate[required]" id="q10_10[day]" name="day1" type="tel" size="2" maxlength="2" value="23" />
<span class="date-separate"> /</span>
<label class="form-sub-label" for="q10_10[day]" id="sublabel_day"> Day </label>
</span><span class="form-sub-label-container">
<input class="form-textbox validate[required]" id="q10_10[month]" name="month1" type="tel" size="2" maxlength="2" value="02" />
<span class="date-separate"> /</span>
<label class="form-sub-label" for="q10_10[month]" id="sublabel_month"> Month </label>
</span><span class="form-sub-label-container">
<input class="form-textbox validate[required]" id="birth_date" name="year1" type="tel" size="4" maxlength="4" value="2013" />
<label class="form-sub-label" for="birth_date" id="sublabel_year"> Year </label>
</span><span class="form-sub-label-container"><img alt="Pick a Date" id="input_10_pick" src="images/calendar.png" align="absmiddle" />
<label class="form-sub-label" for="input_10_pick"> </label>
</span> </div>
</li>
$natdate = date_create(sprintf('%d/%d/%d', $_POST['year1'], $_POST['month1'], $_POST['day1']);
$sql="INSERT INTO memdata(NatDate)
VALUES('$natdate')
当我尝试这个时,我得到Parse错误:语法错误,意外';'
答案 0 :(得分:0)
我不确定,但也许应该是:
$date = $_POST['day1'].'/'.$_POST['month1'].'/'.$_POST['year1'];
i have concat the day , month and year together.
答案 1 :(得分:0)
Day : $_POST["day1"]
Month: $_POST["month1"]
Year: $_POST["year1"]
答案 2 :(得分:0)
MySQL日期字段接受Y-m-d格式的日期。
尝试
$date = $_POST['year1'].'/'.$_POST['month1'].'/'.$_POST['day1'];
答案 3 :(得分:0)
这将获取数据,验证它是一个正确的日期并对其进行格式化,以便您可以将其传递给MySQL(理想情况下通过PDO)。
$date = date_create(sprintf('%d/%d/%d', $_POST['year1'], $_POST['month1'], $_POST['day1']);