I have a problem to store the time in my database, I have a form from which a series of data is sent but for some reason the date is not inserted or only remain in zeros.
<div class="form-group">
<label>Fecha y hora de Inicio:</label>
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-clock-o"></i>
</div>
<input type="date" id="fecha1" name="fecha1">
</div>
</div>
<div class="form-group">
<label>Fecha y hora de Término:</label>
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-clock-o"></i>
</div>
<input type="date" id="fecha2" name="fecha2">
</div>
</div>
There are the inputs that I have in the form since everything else works correctly.
function add () {
global $db, $_POST, $_FILES;
$uniqid = uniqid();
$filename = $uniqid . basename($_FILES["cupon_imagen"]["name"]);
$target_file = $_SERVER['DOCUMENT_ROOT'] .'/admin-kupom/content/cupones/'. $filename;
$filename = 'http://www.kupomcity.com/admin-kupom/content/cupones/' . $filename;
$destacado = 0;
if ($_POST['destacado'] == 1) {
$destacado = 1;
}
if (move_uploaded_file($_FILES["cupon_imagen"]["tmp_name"], $target_file))
{
$sql = "INSERT INTO cupones (
id_comercio,
destacado,
cantidad,
image,
titulo,
texto,
duracion,
created_by,
created_at,
fecha_termino
) VALUES (
:id_comercio,
:destacado,
:cantidad,
:image,
:titulo,
:texto,
:duracion,
:id_usuario,
:data1,
:data2
)";
$stmt = $db->prepare($sql);
$stmt->bindParam(':id_comercio', $_POST['id_comercio'], PDO::PARAM_INT);
$stmt->bindParam(':destacado', $destacado, PDO::PARAM_STR);
$stmt->bindParam(':data1', $_POST['fecha1'], PDO::PARAM_STR);
$stmt->bindParam(':data2', $_POST['fecha2'], PDO::PARAM_STR);
$stmt->bindParam(':cantidad', $_POST['cantidad'], PDO::PARAM_STR);
$stmt->bindParam(':image', $filename, PDO::PARAM_STR);
$stmt->bindParam(':titulo', $_POST['titulo'], PDO::PARAM_STR);
$stmt->bindParam(':texto', $_POST['texto'], PDO::PARAM_STR);
$stmt->bindParam(':duracion', $_POST['duracion'], PDO::PARAM_STR);
$stmt->bindParam(':id_usuario', $_SESSION['user']['id'], PDO::PARAM_INT);
$stmt->execute();
return true;
} else {
return false;
}
}
Here is my function to insert the information into the database, I do not know what is wrong or what I need to insert the dates in the database. The fields are of type date in my database table.