How to enter birth date in comic book?

Asked

Viewed 722 times

1

How to enter date of birth in the comic book?

Erro

Code taken from the form:

$data = $_POST['dtn'];
$dataP = explode('/', $data);
$dataBd = $dataP[2].'-'.$dataP[1].'-'.$dataP[0];

function that sends the data to the bd:

<?php

include("conecta.php");

function insereUsuario($conexao, $dataBd) {
    $query = "insert into usuarios (dataBd) values ({$dataBd})";
    return mysqli_query($conexao, $query);
}
  • 4

    You have already tried to quote the SQL command: ('{$dataBd}')? Without them the bank will interpret as integer values and perform the subtraction operation 2015-10-20 = 1985.

  • Friend thanks, it was quotes, sorry my mistake and thanks again for having helped me.

  • if the column is of the Valores de Tempo there will be no sum no

3 answers

1

The Insert declaration depending on the data type of the column can save a value as shown below.

1 - No quotation marks

SQL, being the column dataBd of the kind Valores de Tempo

insert into usuarios (dataBd) values (2015-10-20)

Resultado (tipo DATE): 0000-00-00

Resultado (tipo DATETIME): 0000-00-00 00:00:00


SQL, being the column dataBd of the kind Valores String or Valores Numéricos

insert into usuarios (dataBd) values (2015-10-20)

Resultado: 1985


2 - With quotation marks

SQL, being the column dataBd of the kind Valores String

insert into usuarios (dataBd) values ('2015-10-20')

Resultado: 2015-10-20


SQL, being the column dataBd of the kind Valores Tempo

insert into usuarios (dataBd) values ('2015-10-20')

Resultado (tipo DATETIME): 2015-10-20 00:00:00

Resultado (tipo DATE): 2015-10-20


SQL, being the column dataBd of the kind Valores Numéricos

insert into usuarios (dataBd) values ('2015-10-20')

Resultado: 2015

Completion

For time or string type columns put quotes in value

$query = "insert into usuarios (dataBd) values ('{$dataBd}')";

0

Try adding date quotes that goes to query.

insert into table (dt) values('2017-10-26');

0

Good morning
I do as follows the INSERTION of values in DB. (mysql)

$pid_paciente=$_POST['pid_paciente'];
$pid_horario=$_POST['pid_horario'];
$pdata_consulta = $_POST['pdata_consulta'];
$sql =  " Insert into consulta " .          
        " ( id_paciente_fk, id_m_h_fk,  id_convenio_fk, data_consulta)" .
        " values " .
        " ( ".$pid_paciente.",".$pid_horario.", 0,'" .$pdata_consulta. "')";


$resultado = mysql_query($sql, $conexao) or die(mysql_error()); 

This is 100% GUARANTEED :).
For an Index to go wrong we have several reasons. But in your question this DATE OF BIRTH and the error is only returning the YEAR.
It seems the variable $_POST['dtn'] only has the year inside.
To check what is within the $_POST['dtn'] I would do so:

$data = $_POST['dtn'];
echo $data . ' a<br>';
$dataP = explode('/', $data);
echo $dataP . ' a<br>';
$dataBd = $dataP[2].'-'.$dataP[1].'-'.$dataP[0];
echo $dataBd . ' a<br>';
exit;

I hope she gave birth to you :)
Hugs.

Browser other questions tagged

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