kadonga
kadonga

Reputation: 11

Get a date PHP value inside of HTML form

I created one HTML FORM where I intend to get some info to store in a database, most of the fields will be filled by the user, but I want one field (date) to appear filled right away with the current date, so I gave this value

<?php echo date("d/m/Y"); ?>

to the FORM field:

<input name="date" type="hidden" value="<?php echo date("d/m/Y"); ?>">

Then I tested it, and instead of get a date on the Database I just get the PHP code.

All this is applicable to one project school, that is the creation of one blog. And right now I intend that the comments FORM created for users store the time/date that the comment was made.

Is there any simple solution for this?

Upvotes: 1

Views: 1654

Answers (2)

chokrijobs
chokrijobs

Reputation: 761

if you want to save this date in your database you must change the date format,

$date = preg_replace( "/([0-9]{2})\/([0-9]{2})\/([0-9]{4})/i", "$3-$2-$1", $_POST['date']);

and you save $date in your database

Upvotes: 0

JohannesAndersson
JohannesAndersson

Reputation: 4620

Yes there is a simple solution, insert it direct in the SQL code.

$sql = "INSERT INTO blog SET date=now()";

Upvotes: 3

Related Questions