dongyou2714 2014-09-25 10:22 采纳率: 0%
浏览 24
已采纳

日期未保存到数据库

I'm creating an appointment plugin, in that for already members and new members are there. in already member area the date entry is not entring into db. but when displaying the variale contains the date. i'm have been checking this from morning but didn't get what is the error. my code is:

 $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>";
        }
    }

The output of the var_dump is array[0] and $app_date is Date:2014-10-22 The db entry is

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

could anyone please point out the mistake in the code if any??

  • 写回答

1条回答 默认 最新

  • dongliuxia9495 2014-09-25 10:35
    关注

    You should convert your string into date object like this:

    $app_date = date('Y-m-d',strtotime($app_date));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看