使用php获取日期时间选择器的值
这段代码是一个html,表示表单上的一个日期选择器控件,我想获取该值,以便将其插入Mysql数据库,im使用Php 我试过这样的方法: $\u POST[我不知道这里应该包括什么] 提前谢谢使用php获取日期时间选择器的值,php,html,datetimepicker,Php,Html,Datetimepicker,这段代码是一个html,表示表单上的一个日期选择器控件,我想获取该值,以便将其插入Mysql数据库,im使用Php 我试过这样的方法: $\u 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
<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')
国民身份证:*
/
白天
/
月
年
$natdate=date\u create(sprintf('%d/%d/%d',$发布['year1'],$发布['month1'],$发布['day1']);
$sql=“插入memdata(NatDate)
值(“$natdate”)
当我尝试此操作时,会出现解析错误:语法错误,意外的“;”我不确定,但可能应该是:
$date = $_POST['day1'].'/'.$_POST['month1'].'/'.$_POST['year1'];
我有一天、一个月、一年的时间。
Day : $_POST["day1"]
Month: $_POST["month1"]
Year: $_POST["year1"]
看看这个例子:
MySQL日期字段接受Y-m-d格式的日期 试一试
这将获取数据,验证它是否是正确的日期,并格式化它,以便您可以将其传递给MySQL(理想情况下通过PDO)
@adictee使用PHP连接数据库的推荐方式-.$natdate=date\u create(sprintf('%d/%d/%d',$\u POST['year1'],$\u POST['month1'],$\u POST['day1']);$sql=“INSERT-INTO-memdata(natdate)值('$natdate')当我尝试此操作时,我得到解析错误:语法错误,意外';”
$date = $_POST['year1'].'/'.$_POST['month1'].'/'.$_POST['day1'];
$date = date_create(sprintf('%d/%d/%d', $_POST['year1'], $_POST['month1'], $_POST['day1']);