Error inserting PHP + Mysqli data

Asked

Viewed 133 times

1

please could help me with the error below, I’m trying to Ravas this code data in a table but when I ask to record is returning the error:

Fatal error: Uncaught Error: Call to Undefined Function d/m/Y() in C: xampp htdocs Portalpib members.php:7 Stack trace: #0 {main} thrown in C: xampp htdocs Portalpib members.php on line 7

Follows code:

<?php

include("conexaobanco.php");

If(isset($_POST['nome'])){
    $nome = filter_input(INPUT_POST, "nome", FILTER_SANITIZE_STRING);
    $datanascimento = DateTime::createFromFormat('d/m/Y'(filter_input(INPUT_POST, "datanascimento", FILTER_SANITIZE_STRING)));
    $datacasamento = DateTime::createFromFormat('d/m/Y'(filter_input(INPUT_POST, "datacasamento", FILTER_SANITIZE_STRING)));
    $dataadmissao = DateTime::createFromFormat('d/m/Y'(filter_input(INPUT_POST, "dataadmissao", FILTER_SANITIZE_STRING)));
    $datadesligamento = DateTime::createFromFormat('d/m/Y'(filter_input(INPUT_POST, "datadesligamento", FILTER_SANITIZE_STRING)));
    $cargo = filter_input(INPUT_POST, "cargo", FILTER_SANITIZE_STRING);
    $endereco = filter_input(INPUT_POST, "endereco", FILTER_SANITIZE_STRING);
    $numero = filter_input(INPUT_POST, "numero", FILTER_SANITIZE_STRING);
    $bairro = filter_input(INPUT_POST, "bairro", FILTER_SANITIZE_STRING);
    $complemento = filter_input(INPUT_POST, "complemento", FILTER_SANITIZE_STRING);
    $cidade = filter_input(INPUT_POST, "cidade", FILTER_SANITIZE_STRING);
    $estado = filter_input(INPUT_POST, "estado", FILTER_SANITIZE_STRING);
    $cep = filter_input(INPUT_POST, "cep", FILTER_SANITIZE_STRING);
    $profissao = filter_input(INPUT_POST, "profissao", FILTER_SANITIZE_STRING);
    $estadocivil = filter_input(INPUT_POST, "estadocivil", FILTER_SANITIZE_STRING);
    $nomeconjuge = filter_input(INPUT_POST, "nomeconjuge", FILTER_SANITIZE_STRING);
    $batizado = filter_input(INPUT_POST, "batizado", FILTER_SANITIZE_STRING);
    $databatismo = DateTime::createFromFormat('d/m/Y'(filter_input(INPUT_POST, "databatismo", FILTER_SANITIZE_STRING)));
    $igrejabatismo = filter_input(INPUT_POST, "igrejabatismo", FILTER_SANITIZE_STRING);
    $email = filter_input(INPUT_POST, "email", FILTER_SANITIZE_STRING);
    $telefone = filter_input(INPUT_POST, "telefone", FILTER_SANITIZE_STRING);


    If(!$conn){
        die("Falha na conexão com o banco de dados, procure o administrador do sistema e informe o erro abaixo: ". "<br>" .mysqli_connect_error());
    }

    If(empty($nome)||empty($email)){
        echo "Preencha os campos corretamente!";
        exit;
    } else {
        $sql = "INSERT INTO TB_MEMBROS (NOME, DATA_NASCIMENTO, DATA_CASAMENTO, DATA_ADMISSAO, DATA_DESLIGAMENTO, CARGO, ENDERECO, NUMERO, BAIRRO, COMPLEMENTO, CIDADE, ESTADO, CEP, PROFISSAO, ESTADO_CIVIL, NOME_CONJUGE, BATIZADO, DATA_BATISMO, IGREJA_BATISMO, EMAIL, TELEFONE) VALUES ('".$nome."', '".$datanascimento->format('Y-m-d')."', '".$datacasamento->format('Y-m-d')."', '".$dataadmissao->format('Y-m-d')."', '".$datadesligamento->format('Y-m-d')."', '".$cargo."', '".$endereco."', '".$numero."', '".$bairro."', '".$complemento."', '".$cidade."', '".$estado."', '".$cep."', '".$profissao."', '".$estadocivil."', '".$nomeconjuge."', '".$batizado."', '".$databatismo->format('Y-m-d')."', '".$igrejabatismo."', '".$email."', '".$telefone."')";
    } If(mysqli_query($conn, $sql)){
        echo "<script>Alert('Conta cadastrada com Sucesso!');</script>";
    } else {
        "Erro: " .$sql. "<br>" .mysqli_connect_error($conn);
    }
}

?>

2 answers

1


All date lines are 'd/m/Y'( the correct would be 'd/m/Y', (

The error was attention even, without passing the comma, it would be like trying to invoke the function d/m/Y, I believe I’m not what you want

  • good, avoid so many parentheses $datanascimento = DateTime::createFromFormat('d/m/Y', filter_input(INPUT_POST, 'datanascimento', FILTER_SANITIZE_STRING));

  • William, really it was this comma, that gives to make the haste, however now it is returning me an error in the line of Insert - "Fatal error: Uncaught Error: Call to a Member Function format() on Boolean in C: xampp htdocs Portalpib membros.php:37 Stack trace: #0 {main} thrown in C: xampp htdocs Portalpib membros.php on line 37"

  • It should probably be on some date, when doing createFromFormat of an error and returns false. Of several var_dump and check the values that appears for each variable

  • Once William had settled, there was an unfilled field, when he passed blank he understood that he was a Boolean. I filled the field and passed... Thank you very much

-1

Dude, by the error he’s not recognizing your date, I’ll leave an example of php’s date syntax here.

  <?php
// Assuming today is March 10th, 2001, 5:16:18 pm, and that we are in the
// Mountain Standard Time (MST) Time Zone

$today = date("F j, Y, g:i a");                 // March 10, 2001, 5:16 pm
$today = date("m.d.y");                         // 03.10.01
$today = date("j, n, Y");                       // 10, 3, 2001
$today = date("Ymd");                           // 20010310
$today = date('h-i-s, j-m-y, it is w Day');     // 05-16-18, 10-03-01, 1631 1618 6 Satpm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.');   // it is the 10th day.
$today = date("D M j G:i:s T Y");               // Sat Mar 10 17:16:18 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h');     // 17:03:18 m is month
$today = date("H:i:s");                         // 17:16:18
$today = date("Y-m-d H:i:s");                   // 2001-03-10 17:16:18 (the MySQL DATETIME format)
?>

and the link: http://php.net/manual/en/function.date.php

  • Hello Ricardo, thank you very much, I was really removed the date format and solved, but for test redone, I left on the bench a date field with date format and other as varchar, what I let varchar included normally, what I left date was all zeroed (0000-00-00)How can I fix this?

Browser other questions tagged

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