Jump to content

[SOLVED] get the current date and time in string format to store in a variable


johnfuller

Recommended Posts

Hi,

 

I am new to PHP so I am having a little difficulty getting the date a time into a string that I have called $postdate

 

I have a form that is submitting a string to my php file 'input.php'. I am then trying to add the date and time to that string and save it in a file 'data.dat'. I thought the code below would do it but I get an error.

 

 

<?php

$input = $_POST['msg'];

 

 

 

$postdate = date('D, d M Y H:i:s T')

$data = $postdate . " " . $input

 

$file = 'filepath/data.dat';

$fh = fopen($file, 'a') or die('Could not open file!');

fwrite($fh, $data) or die('Could not write to file');

fclose($fh);

?>

 

 

The error I am getting is this:

 

 

Parse error: syntax error, unexpected T_VARIABLE in filepath/input.php on line 10

 

 

Can anyone help me get this working?

 

<?php
$input = $_POST['msg'];
$postdate = date('D, d M Y H:i:s T');
$data = $postdate . " " . $input;

$file = 'filepath/data.dat';
$fh = fopen($file, 'a') or die('Could not open file!');
fwrite($fh, $data) or die('Could not write to file');
fclose($fh);
?>

Thanks! I made the most basic mistake :D

 

I am now trying to make my script include line breaks. Below is what I tried but it is not working. Any help would be appreciated.

 

<?php
$input = $_POST['msg'];
$postdate = date('D, d M Y H:i:s T');
$data = $postdate . "\n" . "\n" . $input . "\n";

$file = 'filepath/data.dat';
$fh = fopen($file, 'a') or die('Could not open file!');
fwrite($fh, $data) or die('Could not write to file');
fclose($fh);
?>

 

The above code just puts a space between each variable but I need the second variable to appear 2 lines down in the file and then to leave a new line afterwards so that the next time a user enters a string there will be a gap. Hope I am making sense.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.