0
I have a function that performs an update:
function alterarConta(){
$dataemissao = $_POST['dataemissao'];
$id = $_POST['id'];
$select_fornecedores = $_POST['select_fornecedores'];
$valor = $_POST['valor'];
$datavencimento = $_POST["datavencimento"];
$especie = $_POST['especie'];
$observacao = $_POST['observacao'];
$banco = abrirBanco();
$sql = " UPDATE contas SET c.dataemissao = '$dataemissao', c.id_fornecedor = '$select_fornecedores', c.valor = '$valor', c.datavencimento = '$datavencimento', c.especie = '$especie', c.observacao = '$observacao' FROM contas c INNER JOIN pessoa f ON (c.id_fornecedor = f.id) WHERE c.id = '$id'";
$banco->query($sql);
$banco->close();
header('Location: consulta_contas.php');
}
I’m having a hard time, I can’t find where you’re wrong.
What error is displayed? Or what is the difficulty?
– Don't Panic
Leticia, take a look here to learn how to perform a
UPDATE
withINNER JOIN
can help you.– gato
@Everson can do an UPDATE with INNER JOIN yes.
– gato
I think what @Everson meant was that it is not possible to perform an UPDATE with FROM.
– Pantoja
@Pantoja that’s right, thank you!
– Don't Panic
The error that appears: Cannot add or update a Child Row: a Foreign key Constraint fails (
despesas
.contas
, CONSTRAINTcontas_ibfk_1
FOREIGN KEY (id_fornecedor
) REFERENCESpessoa
(id
))– veroneseComS
I tried something like: $sql = "UPDATE accounts AS c INNER JOIN person AS p ON(c.id_vendor = p.id) SET c.outgoing date = '$outgoing date', c.id_vendor = '$select_vendors', c.value = '$value', c.outgoing date = '$due date', c.especie = '$specify', c.note = '$note' WHERE c.id = '$id' "; But it hasn’t worked out yet. I added a photo with the structure of the tables
– veroneseComS