Solved

Inserting date in PHP

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

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now