1
Good people, I’m having a problem making an insert in the postgresql database, this is my insert:
INSERT INTO dynfipemarca (codigomarca,marca,tipo, OID, fgenabled, fgsystem , nrversion) VALUES
(:codigomarca,'" . pg_escape_string(utf8_encode($nomeMarca)) . "',:tipo, '" . $codigoMarca . "' , 1 , 0, 0)
I receive back end data from an API, and insert dynamically, here’s my Binding:
$cadastrarMarca = conectar()->prepare($sql);
$cadastrarMarca->bindValue(":codigomarca",$codigoMarca,PDO::PARAM_INT);
$cadastrarMarca->bindValue(":marca", $nomeMarca);
$cadastrarMarca->bindValue(":tipo",$tipo);
$cadastrarMarca->execute();
and the mistake that’s coming to me is this
PHP Warning: Pdostatement::bindValue(): SQLSTATE[HY093]: Invalid Parameter number:tag
i identified where the error is, $register?
Where is the parameter
:marca
in SQL?– Laércio Lopes
is that actually in Insert where I enter the value of the mark, I was doing with :mark, but started to error when inserting a mark with accent, then I changed and put the function pg_escape_string and utf8_encode, as it is there in the example. Then gives the error in this parameter, I can do the encoding directly in the parameter?
– Bruno Elias de Souza
In this SQL:
INSERT INTO dynfipemarca (codigomarca,marca,tipo, OID, fgenabled, fgsystem , nrversion) VALUES (:codigomarca,'" . pg_escape_string(utf8_encode($nomeMarca)) . "',:tipo, '" . $codigoMarca . "' , 1 , 0, 0)
has the parameter:tipo
and the parameter:codigomarca
, why don’t you put the:marca
also while doing the bind his?– Laércio Lopes
As I explained, it started to make a mistake to insert accents, you know? then I removed the parameter, and displayed what comes from the back end within the encoding functions
– Bruno Elias de Souza
So why do the bind of a parameter you removed? Remove the line:
$cadastrarMarca->bindValue(":marca", $nomeMarca);
– Laércio Lopes
Hummm Beauty Laércio, in the case as I am inserting what comes from the back end and is already set the value does not need to bind, I understand. Removed and worked, thanks.
– Bruno Elias de Souza
You tried to keep the parameter
:marca
and leave SQL asINSERT INTO dynfipemarca (codigomarca,marca,tipo, OID, fgenabled, fgsystem , nrversion) VALUES (:codigomarca,'" . pg_escape_string(utf8_encode(:marca)) . "',:tipo, '" . $codigoMarca . "' , 1 , 0, 0)
? That way I could keep thebind
.– Laércio Lopes
yes I tried, but stopped inserting the marks, then I do another test and see better what happens
– Bruno Elias de Souza
Arrow up in the answer?
– Laércio Lopes