gpt4 book ai didi

php - 日期未保存到数据库

转载 作者:行者123 更新时间:2023-11-29 23:44:06 24 4
gpt4 key购买 nike

我正在创建一个约会插件,其中已有成员(member)和新成员(member)都可以使用。在已有的成员(member)区域中,日期条目未进入数据库。但显示变量时包含日期。我从早上就一直在检查这个,但没有明白错误是什么。我的代码是:

 $source = mysql_real_escape_string(trim($_POST['apdatetime']));
$datetime = explode(',', $source);
$dates = $datetime[0];
$app_time = $datetime[1];
if($app_time < 12){
$app_session = 'am';
}
else{
$app_session ='pm';
}
$splitdatet = explode('/', $dates);
$yyear = $splitdatet[2];
$mmonth = $splitdatet[1];

$ddate = $splitdatet[0];
$app_date = $yyear . "-" . $mmonth . "-" . $ddate;


if ($_POST['isnewpatient'] == "false") {


//$cSql = "select * from " . WP_contact . " where appointments_c_patientid='" . trim($_POST['ptntid']) . "' ";
$cSql = "select * from " . WP_eemail_TABLE_SUB . " where eemail_patient_id='" . trim($_POST['ptntid']) . "' ";

$data = $wpdb->get_results($cSql);
if (empty($data )) {
$err = 1;
echo "<div id='message' class='aerror'>No such patient ID exists....</div>";
} else {

@$mobile = htmlspecialchars(stripslashes($data[0]->eemail_mobile_sub));
@$email = htmlspecialchars(stripslashes($data[0]->eemail_email_sub));
@$name = htmlspecialchars(stripslashes($data[0]->eemail_name_sub));
$sqlss = "insert into " . WP_Appointments .
" (`appointments_patient_id`,`appointments_date`,`appointments_time`,`appointments_session`,`appointments_reg_date`) VALUES ('" .
mysql_real_escape_string(trim($_POST['ptntid'])) . "','" .
$app_date . "','" .
$app_time . "','" .
$app_session . "',CURRENT_TIMESTAMP() )";
$dd=$wpdb->get_results($sqlss);
var_dump($dd);
echo 'Date:'.$app_date;
// return $suc;
echo "<div id='message' class='asuccess' >Request has been sent for appointment</div>";
}
}

var_dump 的输出为 array[0],$app_date 为 Date:2014-10-22数据库条目是

appointments_id           :393
appointments_patient_id : 9999999999
appointments_date : 0000-00-00
appointments_time : 9:00
appointments_session : am
appointments_reg_date : 2014-09-25 14:21:35

谁能指出代码中的错误吗?

最佳答案

您应该将字符串转换为日期对象,如下所示:

$app_date = date('Y-m-d',strtotime($app_date));

关于php - 日期未保存到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26036147/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com