1

I have following form for text input - saving it to my php variable - and I am displaying it on page. I need to create a record that would show on my page: "Last update was: dd-mm-yyyy" - aka: display the last time when my form was submitted. I guess I will need the date function - I just cannot figure out how to trigger creating the date based on form submission. I appreciate any help, thank you very much!

<form action=""a.php"" method="POST" name="uploadText">
<label for="textarea">text</label>
<input type="textarea" name="textUpload" id="homepageText">
<input type="submit" name="submitButton" id="submitButton" value="submit">
</form>

and a.php

$homepageText = $_POST["textUpload"];
Helen3061371
  • 135
  • 8
  • You have to store the value somewhere, like into a database (which I personally suggest) or a file, I don't think you can store that elsewhere, unless you use cookies, but that meeans that they won't be universal and that if someone changes browser it just won't work. Conclusion: use a database, store the value (datetime in this case) into a row of the database and update it each time the form gets submitted. – briosheje Dec 04 '13 at 12:07

2 Answers2

0

You have to save the time in a file or in a database, because variables are not permanent.

You could for example save a timestamp with time() and save it in a file using fopen(), fwrite() and fclose()

Maarkoize
  • 2,601
  • 2
  • 16
  • 34
  • Also, take care about filewrite permissions... (chmod 777)... I mean.. this: http://stackoverflow.com/questions/9319619/php-and-file-write-permissions – briosheje Dec 04 '13 at 12:09
0

You can do any one of the following:

  • You can build a timestamp in PHP (format: YYYY-MM-DD HH:MM:SS) and insert it into database.

  • You can build another column of type TIMESTAMP and set it's default value to CURRENT_TIMESTAMP in the column definition.

  • You can save the time in a file and use filemtime() to return the time.

Joke_Sense10
  • 5,341
  • 2
  • 18
  • 22
  • Ohh.. Because every entry always rewrites the last one (like my textUpload variable) I was hoping that I could do it without dtb.. Could I use an array for storing the information instead? And the main problem remains: how do I specify in PHP language that I want to store(in dtb or $) the date of submitting the form (and not the current one)? Thanks a lot. – Helen3061371 Dec 04 '13 at 12:26
  • You can store it an array but not permanently but you can store it in `session` permanently.I suggest you to store it in database the moment you submit the form.check for option two in my solution, where you just need to add anew column of type `timestamp` and default value has `CURRENT_TIMESTAMP ` in database. while inserting you dont have to insert the time as the database automatically does it..so it's pretty simple. – Joke_Sense10 Dec 04 '13 at 12:33
  • 1
    I see the benefit of using the database timestamp function now, true, it is straight forward. Thank you very much for the comment. – Helen3061371 Dec 04 '13 at 12:46