4
Well, I need to do an insert and I use PHP OO, but how do I do this? According to my code is registering, but is not working perfect.
I’m doing something wrong ? Do not give any error message, just say you are successfully registered!
try {
$sql = $conn->prepare("INSERT INTO tbl_PESSOAS (
COD_IDENT_IGREJ,
TXT_NOMEX_PESSO,
TXT_FONEX_PESSO,
DAT_NASCI_PESSO,
FLG_SEXOX_PESSO,
FLG_IDENT_PESSO,
TXT_EMAIL_PESSO,
TXT_SENHAX_USUAR,
TXT_ENDER_CEPXX,
TXT_ENDER_BAIRR,
TXT_ENDER_LOGRA,
TXT_ENDER_NUMER,
TXT_ENDER_COMPL,
COD_IDULT_ATUAL,
DAT_ULTIM_ATUAL)
VALUES (:COD_IDENT_IGREJ,
:TXT_NOMEX_PESSO,
:TXT_FONEX_PESSO,
:DAT_NASCI_PESSO,
:FLG_SEXOX_PESSO,
:FLG_IDENT_PESSO,
:TXT_EMAIL_PESSO,
:TXT_SENHAX_USUAR,
:TXT_ENDER_CEPXX,
:TXT_ENDER_BAIRR,
:TXT_ENDER_LOGRA,
:TXT_ENDER_NUMER,
:TXT_ENDER_COMPL,
:COD_IDULT_ATUAL,
:DAT_ULTIM_ATUAL)");
$collection = array(
'COD_IDENT_IGREJ' => $codIgreJ,
'TXT_NOMEX_PESSO' => $lbl_NOME,
'TXT_FONEX_PESSO' => $lbl_TELEFONE,
'DAT_NASCI_PESSO' => $dte_ANIVERSARIO,
'FLG_SEXOX_PESSO' => $lbl_SEXO,
'FLG_IDENT_PESSO' => $lbl_FLAG_IDENT,
'TXT_EMAIL_PESSO' => $lbl_EMAIL,
'TXT_SENHAX_USUAR' => $lbl_SENHA,
'TXT_ENDER_CEPXX' => $lbl_CEP,
'TXT_ENDER_BAIRR' => $lbl_BAIRRO,
'TXT_ENDER_LOGRA' => $lbl_RUA,
'TXT_ENDER_NUMER' => $lbl_NUMERO,
'TXT_ENDER_COMPL' => $lbl_COMPLEMENTO,
'COD_IDULT_ATUAL' => $lbl_COD_ID,
'DAT_ULTIM_ATUAL' => $lbl_NOW
);
$sql->execute($collection);
/* $UltAiAdd = $conn->lastInsertId();
$sql2 = $conn->prepare("INSERT INTO tbl_PESSOA_CELULA VALUES ( COD_IDENT_PESSO = :COD_IDENT_PESSO, COD_IDENT_CELUL = :COD_IDENT_CELUL, FLG_IDENT_PESSO = :FLG_IDENT_PESSO, "
. "COD_IDULT_ATUAL = :COD_IDULT_ATUAL, DAT_ULTIM_ATUAL = :DAT_ULTIM_ATUAL)");
$sql2->bindParam(":COD_IDENT_PESSO", $UltAiAdd);
$sql2->bindParam(":COD_IDENT_CELUL", $codCel);
$lbl_FLAG_PE = 'M';
$sql2->bindParam(":FLG_IDENT_PESSO", $lbl_FLAG_PE);
$sql2->bindParam(":COD_IDULT_ATUAL", $lbl_COD_ID);
$sql2->bindParam(":DAT_ULTIM_ATUAL", $lbl_NOW);
$sql->execute(); */
} catch (Exception $exc) {
error_log($exc->getMessage());
echo "058"; //Erro no cadastro.
}
echo "057"; //Cadastrado com sucesso!
What is not working perfect, can show us?
– Ivan Ferrer
Just not nothing. No error, but when I go to the data table it is not registered.
– Renan Rodrigues
instead of using bindParam, try to pass everything as a direct array in execute:
$collection[] = ['COD_IDENT_PESSO", $UltAiAdd]; $sql->execute($collection);
– Ivan Ferrer
It is that the good bindParam you have to treat the data type.
– Ivan Ferrer
Let’s go continue this discussion in chat.
– Renan Rodrigues
you need to make the PDO imprint the error ...
$sql->execute() ? print 'sucesso' : print_r($sql->errorInfo());
do the same to$sql2
– rray
Take a look at her
– Renan Rodrigues
I do not understand php, but I would inser so:
"INSERT INTO tbl_NomedaTabela (campo1, campo2 VALUES (:valor1, :valor2)"
– emanuelsn
lacked kinship in
$sql->errorInfo()
... I forgot to put.– rray
@rray is not working the command.
– Renan Rodrigues
I need the error to appear on the console as it would ?
– Renan Rodrigues
Since there are two Inserts a referential integrity possibility, the value entered(id) in the second table does not exist pq the first Insert failed either by a constraint or any other reason.
– rray
If this calling this Insert via ajax, you need to take the return of ajax and give a
console.log()
in your javascript.– rray
the
$sql->errorInfo()
returned some message?– rray
Had no log, continued the same way.
– Renan Rodrigues
This error says that there are more columns than values in Insert, there must be some wrong placeholder.
– rray