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

从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?

图片转代码服务由CSDN问答提供 功能建议

我是php和java等的新手,因此我正在学习它,但是我 我看了每个可能的选项,并尝试调整,但由于某种原因,我的代码仍然无法正常工作。 我在php文件中调用日期和时间,它将日期和时间提交给电子邮件,但不会将其放在我的csv文件中(留下一个空白列)。

I 用第一行设置日期和时间然后csv提交在那之后(所以我不通过我的html或任何东西调用日期和时间

php

  $ combinedDT = date('Ymd H:i:s',strtotime(“$ date $ time”)); 
 
 //开始提交csv提交表
 
 $  filename =“wedding_website_email_form.csv”; 
 $ string = array($ _ POST ['combinedDT'],$ _ POST ['name_surname'],$ _ POST ['telephone'],$ _ POST ['email_from'],$ _ POST [  'rsvp'],$ _ POST ['参与者'],$ _ POST ['歌曲'],$ _ POST ['评论']); 
 
if(file_exists($ filename)){
 $ file = fopen($  filename,'a'); 
 fputcsv($ file,$ string); 
} else {
 $ file = fopen($ filename,'a'); 
 $ head_data = array(“combinedDT”,“  name_surname“,”电话“,”email_from“,”rsvp“,”与会者“,”歌曲“,”评论“); 
 fputcsv($ file,$ head_data); 
 fputcsv($ f  ile,$ string); 
} 
 
 nclclose($ file); 
   
 
 

是否有不同的方式来调用它而不是有效的电子邮件功能 ?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题