johnfuller Posted August 9, 2008 Share Posted August 9, 2008 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? Link to comment https://forums.phpfreaks.com/topic/118907-solved-get-the-current-date-and-time-in-string-format-to-store-in-a-variable/ Share on other sites More sharing options...
papaface Posted August 9, 2008 Share Posted August 9, 2008 <?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); ?> Link to comment https://forums.phpfreaks.com/topic/118907-solved-get-the-current-date-and-time-in-string-format-to-store-in-a-variable/#findComment-612287 Share on other sites More sharing options...
johnfuller Posted August 9, 2008 Author Share Posted August 9, 2008 Thanks! I made the most basic mistake 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. Link to comment https://forums.phpfreaks.com/topic/118907-solved-get-the-current-date-and-time-in-string-format-to-store-in-a-variable/#findComment-612293 Share on other sites More sharing options...
johnfuller Posted August 9, 2008 Author Share Posted August 9, 2008 Ok I managed to fix this by putting "<br><br>" instead of "/n" Thanks everyone! Link to comment https://forums.phpfreaks.com/topic/118907-solved-get-the-current-date-and-time-in-string-format-to-store-in-a-variable/#findComment-612303 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.