dpp3047 2018-09-21 12:25
浏览 67
已采纳

从PHP表单发布到CSV文件时不调用DateTime

I am new to php and java etc, so i'm hacking it as i'm learning, but i've looked at every possible option and tried to adjust, but for some reason my code is still not working. I am calling the date and time in php file, and it submits the date and time to the email, but does not place it in my csv file (leaves a blank column).

I set the date and time with the first line and then the csv submit is after that (so i do not call the date and time via my html or anything

php

    $combinedDT = date('Y-m-d H:i:s', strtotime("$date $time"));

//start of the csv submission form

$filename = "wedding_website_email_form.csv";
$string = array($_POST['combinedDT'],$_POST['name_surname'],$_POST['telephone'],$_POST['email_from'],$_POST['rsvp'],$_POST['attendees'],$_POST['song'],$_POST['comments']);  

if (file_exists($filename)) {
        $file = fopen($filename, 'a');
        fputcsv($file, $string );
    } else {
        $file = fopen($filename, 'a'); 
        $head_data=array("combinedDT","name_surname","telephone","email_from","rsvp","attendees","song","comments");
        fputcsv($file,$head_data);
        fputcsv($file, $string );
    }

fclose($file);

Is there a different way to call it than to the email function that works?

  • 写回答

1条回答 默认 最新

  • duanjiwei1283 2018-09-21 12:31
    关注

    It looks like you're calculating

    $combinedDT = date('Y-m-d H:i:s', strtotime("$date $time"));

    But then calling the line for your CSV from the global $_POST variable, not the locally calculated variable.

    $string = array($combinedDT, $_POST['name_surname']....);

    Should enter the locally calculated DateTime into the CSV.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch