-1

此代码是一个 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">&nbsp;/</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">&nbsp;/</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"> &nbsp;&nbsp;&nbsp; </label>
          </span> </div>
  </li>

$natdate = date_create(sprintf('%d/%d/%d', $_POST['year1'], $_POST['month1'], $_POST['day1']);

 $sql="INSERT INTO memdata(NatDate)
VALUES('$natdate')

当我尝试这个时,我得到解析错误:语法错误,意外';'

4

4 回答 4

0

我不确定,但也许应该是:

$date = $_POST['day1'].'/'.$_POST['month1'].'/'.$_POST['year1'];

i have concat the day , month and year together.

于 2013-02-25T11:55:19.503 回答
0
Day :  $_POST["day1"]
Month: $_POST["month1"]
Year:  $_POST["year1"]

看看这个例子: http ://www.w3schools.com/php/php_post.asp

于 2013-02-25T11:56:27.310 回答
0

MySQL 日期字段接受 Ymd 格式的日期。

尝试

$date = $_POST['year1'].'/'.$_POST['month1'].'/'.$_POST['day1'];
于 2013-02-25T12:04:50.743 回答
0

这将获取数据,验证它是否是正确的日期并对其进行格式化,以便您可以将其传递给 MySQL(最好通过 PDO)。

$date = date_create(sprintf('%d/%d/%d', $_POST['year1'], $_POST['month1'], $_POST['day1']);
于 2013-02-25T12:07:04.970 回答