How to take a date through a form and insert it into the database

Asked

Viewed 16 times

-1

I have the following problem: I am not able to take the current time and insert it in the bank.

<div class="container">
			<h2>Registrando ponto</h2>

			<form class="form" method="POST" action="registroHora.php">

				<button type="submit" class="btn btn-primary"     name="codEntrada">Entrada</button>
				<button type="submit" class="btn btn-primary" name="codSaida">Saída</button>
			</form>
		</div>

<?php
session_start();
include_once("conexao.php");

$codEntrada = $_POST['codEntrada'];
$codSaida = $_POST['codSaida'];
$codUser = $_POST['codUser'];


$sql = "insert into registroPonto (codEntrada, codSaida, codUser)
    values('$codEntrada', '$codSaida', '$codUser')";

$sql = mysqli_query($conn, $sql);

if(mysqli_insert_id($conn)){
    $_SESSION['msg'] = "Ponto Registrado";
    header('location: area-usuario.php');
}
else
{
    $_SESSION['msg'] = "Usuário não Cadastrado.";
    header('location: cadastro.php');
}

?>

    create table cadastroUsuario(
    codUser int not null auto_increment primary key,
    userNome varchar(100) not null,
    userEmail varchar(100) not null,
    userSenha varchar(100) not null,
    userConfirmaSenha varchar(100) not null
);

create table registroPonto(
    codPonto int not null auto_increment primary key,
    codEntrada datetime not null,
    codSaida datetime not null,
    codUser int not null,
    constraint fk_ponto_usuario FOREIGN KEY (codUser)
    REFERENCES cadastroUsuario (codUser)
);

1 answer

0

You can go straight to your registered pageHora.php using

date('Y-m-d H:i:s')

or puts HTML into an input

<input type="date" name="datahora" value="<?=date('Y-m-d H:i:s')?>" />

or directly in the SQL Insert command, in this case, in Mysql Voce can use the 'NOW()'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.