如您所知,数据库中的日期格式是 Ymd,我需要在 dmY 中回显日期。这是回声的代码:
<td class="pk">From</td>
<td width="50%" class="pk_2"><input name="personal_ic_from" type="text" class="tcal" id="personal_ic_from" value="<?php
echo date_create($personal_ic_from)->format('d-m-Y');
?>" readonly="readonly"/>
</td>
我的问题是,在用户更改日期后personal_ic_from
,我需要在更新查询中将日期格式从 dmY 转换回 Ymd(这是数据库中日期的标准格式)。但是,我无法做到这一点..
这是我的更新查询:
<?php
$personal_ic_from = $_POST['personal_ic_from'];
$personal_ic_to = $_POST['personal_ic_to'];
$personal_ic_num = $_POST['personal_ic_num'];
$personal_ic_old_num = $_POST['personal_ic_old_num'];
$personal_ic_issuing_autho = $_POST['personal_ic_issuing_autho'];
$personal_ic_issuing_num = $_POST['personal_ic_issuing_num'];
$personal_ic_issuing_date = $_POST['personal_ic_issuing_date'];
$personal_ic_date_expiry = $_POST['personal_ic_date_expiry'];
$personal_ic_place_issue = $_POST['personal_ic_place_issue'];
$personal_ic_country_issue = $_POST['personal_ic_country_issue'];
$personal_ic_country = $_POST['personal_ic_country'];
mysql_query("UPDATE personal_id_ic SET personal_ic_from = '".mysql_real_escape_string($_POST["personal_ic_from"])."', personal_ic_to = '".mysql_real_escape_string($_POST["personal_ic_to"])."', personal_ic_num = '".mysql_real_escape_string($_POST["personal_ic_num"])."', personal_ic_old_num = '".mysql_real_escape_string($_POST["personal_ic_old_num"])."', personal_ic_issuing_autho = '".mysql_real_escape_string($_POST["personal_ic_issuing_autho"])."', personal_ic_issuing_num = '".mysql_real_escape_string($_POST["personal_ic_issuing_num"])."', personal_ic_issuing_date = '".mysql_real_escape_string($_POST["personal_ic_issuing_date"])."', personal_ic_date_expiry = '".mysql_real_escape_string($_POST["personal_ic_date_expiry"])."', personal_ic_place_issue = '".mysql_real_escape_string($_POST["personal_ic_place_issue"])."', personal_ic_country_issue = '".mysql_real_escape_string($_POST["personal_ic_country_issue"])."', personal_ic_country = '".mysql_real_escape_string($_POST["personal_ic_country"])."' WHERE LAS_login_id = '".mysql_real_escape_string($_POST["LAS_login_id"])."'");
?>
如何将格式从 dmY 转换回 Ymd,以便数据库可以保存新日期?我尝试将查询更改为 for personal_id_ic
,但是当我使用此代码时,数据库保存了一个随机日期,而不是用户选择的日期:
mysql_query("UPDATE personal_id_ic SET personal_ic_from = '".mysql_real_escape_string($_POST["personal_ic_from, %Y-%m-%d"])."' WHERE LAS_login_id = '".mysql_real_escape_string($_POST["LAS_login_id"])."'");