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
Solved

Inserting date in PHP

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

809 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