• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • Last Modified:

Inserting date in PHP

Hello.

I am using some code to write form data to a text file.  The code is:

<?php 

$username = $_POST['user']; 
$email = $_POST['mail']; 


//the data 
$data = "$username | $email\n"; 

//open the file and choose the mode 
$fh = fopen("users.txt", "a"); 
fwrite($fh, $data); 

//close the file 
fclose($fh); 

?> 

Open in new window


This writes a name and Email address entered into a form into the text file users.txt.

What I would like is after the email address for it to enter today's date as well.  How can I achieve this?

Many thanks as always.
0
JakeSpencer
Asked:
JakeSpencer
1 Solution
 
Peter KwanCommented:
You may make reference to the following:

http://php.net/manual/en/function.date.php
0
 
Beverley PortlockCommented:
Change

$data = "$username | $email\n";

to

$data = "$username | $email ". date("Y-m-d")  ."\n";

The exact format can be fiddled with by using the link provided above by pkwan

0
 
Loganathan NatarajanLAMP DeveloperCommented:
try this,

<?php 

$username = $_POST['user']; 
$email = $_POST['mail']; 
$date = date("m/d/Y");

//the data 
$data = "$username | $email | $date \n"; 

//open the file and choose the mode 
$fh = fopen("users.txt", "a"); 
fwrite($fh, $data); 

//close the file 
fclose($fh); 

?>

Open in new window

0
 
JakeSpencerAuthor Commented:
Perfect, thanks guys
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now