Solved

Inserting date in PHP

Posted on 2011-02-22
4
269 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
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 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

832 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