?
Solved

Inserting date in PHP

Posted on 2011-02-22
4
Medium Priority
?
276 Views
Last Modified: 2012-08-14
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
Comment
Question by:JakeSpencer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 34950322
You may make reference to the following:

http://php.net/manual/en/function.date.php
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 34950340
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
 
LVL 36

Accepted Solution

by:
Loganathan Natarajan earned 2000 total points
ID: 34950349
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
 

Author Comment

by:JakeSpencer
ID: 34950377
Perfect, thanks guys
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question