dpp3047 2018-09-21 12:25 采纳率: 0%
浏览 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.

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

报告相同问题?