save dates in a mysql table

0

my users table is composed of three fields name varchar 15, comment varchar 255 and date date, I want to send a comment to save the date of the publication of the comment in the field date

<form method="get" action="conexion.php">
<input type="text" name="name">
<textarea rows="5" cols="5" name="commento"></textarea>
<input type="submit" value="enviar">
</form>



<?php
$conexion = mysql_connect('localhost', 'root', 'admin');
mysql_select_db('test', $conexion) or die (mysql_error());

$name = $_GET['name'];

$commento = $_GET['commento'];

$fecha= date("Y-m-d H:i:s");
$sql = "INSERT INTO commenti (name, commento, fecha) VALUES ('$name', '$commento', '$fecha')" ;
mysql_query($sql);

echo $name;
echo $commento;
echo $fecha;

?>

in console when I execute the statement

select * from commenti 
output
empty set
    
asked by steven 08.05.2017 в 15:29
source

2 answers

0

You can try adding functions CURRENT_TIME() or now() to the query

INSERT INTO commenti (name, commento, fecha) VALUES ('$name', '$commento', NOW())

or

INSERT INTO commenti (name, commento, fecha) VALUES ('$name', '$commento', CURRENT_TIME())

or you can try to generate the date in php and insert the variable in the query.

$fecha= date("Y-m-d H:i:s");
    
answered by 08.05.2017 / 15:35
source
1

To add the system date

INSERT INTO commenti ('name', 'commento', SYSDATE()) VALUES ($name, $commento, $fecha)
    
answered by 08.05.2017 в 15:45