PHP:将今天的日期从表单发布到文本文件



i在HTML中创建了一个表单,并且输入将其发布到带有PHP的文本文件中。当输入提交到文本文件时,我想添加日期邮票。使用我的代码,它不会打印出日期。

php文件:

<?php
if(isset($_POST['email'])) {
$file = "loginRequest.txt";
$company_name = $_POST['Company_name'];
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$account_num = $_POST['Account_num'];
$address = $_POST['Address'];
$city = $_POST['City'];
$state = $_POST['State'];
$zip = $_POST['Zip'];
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$date = $_POST['todayDate'];

$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/';
$email_message = "Form details below.rn";
$email_message .= "First Name: $first_namern";
$email_message .= "Last Name: $last_namern";
$email_message .= "Account#: $account_numrn";
$email_message .= "Address: $addressrn";
$email_message .= "City: $cityrn";
$email_message .= "State: $statern";
$email_message .= "Zip: $ziprn";
$email_message .= "Email: $email_fromrn";
$email_message .= "Telephone: $telephonern";
$email_message .= "Company Name: $company_namernrn";
$fp = fopen($file, "a") or die("Couldn't open $file for writing!");
fwrite($fp, $email_message) or die("Couldn't write values to file!");
fclose($fp);
?>

我在html中的表格:

 <!-- WORK IN PROGRESSS: this is the hidden input for the date stamp-->
 <tr>
 <td>
 <input type="hidden" name="startdate" id="todayDate"/>
 </td>
 </tr>

JavaScript逻辑以获取日期:

<!-- hidden date stamp logic -->
<script type="text/javascript">
function getDate(){
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10){dd='0'+dd} if(mm<10){mm='0'+mm}
today = yyyy+""+mm+""+dd;
document.getElementById("todayDate").value = today;
};
//call getDate() when loading the page
getDate();  

更改$ _post ['tever -date'];到$ _post ['startDate'];

您也没有任何实际打印日期的东西,以便您可以看到它。您需要添加:

$email_message .= "Date: $datern";

最新更新