0
The code below only inserts in the requested table, already in the requested product has_does not insert. What error ?
public function criarPedido(){
$consulta = 'INSERT into pedido(data, valorTotal, cliente_id) values(:data,:valorTotal,:clienteId)';
$stmt = $this->PDO->prepare($consulta);
$stmt->bindParam(':data', $this->data);
$stmt->bindParam(':valorTotal', $this->valorTotal);
$stmt->bindParam(':clienteId', $this->clienteId);
$stmt->execute();
echo "Produto cadastrado.";
/////////////////////////////////////// produto_has_pedido /////////////////////////////////////////////////
$consulta2 = 'INSERT into produto_has_pedido(produto_id, pedido_id) values('.$this->produto_id.', '.$this->PDO->lastInsertId().')';
$stmt2 = $this->PDO->prepare($consulta2);
$stmt2->execute();
}
Also publish which error msg displayed and which line! So it is easier to help you!
– Wilson Faustino
The problem is this, no error appears, it simply does not insert in the product table_has_request
– Leonardo Henrique
Try to use
print_r($this->PDO->errorInfo());
to assess the error!– Wilson Faustino
what are the table fields, pk, fk? what values you are trying to insert? wouldn’t that be a duplicate pk problem? vc confiriu esses valores '.$this->produto_id. ', '.$this->PDO->lastInsertId(). ' pq pode ser null...
– HudsonPH
Foreign key is requested
– Leonardo Henrique
an echo at these values '.$this->producto_id. ', '.$this->PDO->lastInsertId(). ' to see if they are not empty
– HudsonPH
It correctly returns the product id and last order id
– Leonardo Henrique