0
I have the following functions: File registra_account.php:
if(isset($_POST['acao'])){
if($_POST['acao'] == "inserir"){
inserirConta();
}
if($_POST['acao'] == "alterar"){
alterarConta();
function selectIdConta($id){
$banco = abrirBanco();
$sql = "SELECT * FROM contas c INNER JOIN pessoa p ON(c.id_fornecedor = p.id) WHERE c.id = ".$id;
$resultado = $banco->query($sql);
$banco->close();
$conta = mysqli_fetch_assoc($resultado);
return $conta;
}
function alterarConta(){
$id_conta_selecionada = $_POST['id'];
$sql = " UPDATE contas SET valor = '$valor' WHERE id= '$id_conta_selecionada' ";
$banco->query($sql);
$banco->close();
I realized that if I change the '$id_conta_selected' by an id registered in the database, the query works, however, through the POST method I am not able to get the account id.
File alterar_conta.php:
<?php
include_once("registra_conta.php");
require_once("conexao.php");
if(!$_SESSION['usuario']){
header('Location: index.php?erro=1');
}
$conta = selectIdConta($_POST["id"]);
?>
I have the form:
<form name="dadosConta" action="registra_conta.php" method="POST">
<input type="hidden" name="acao" value="alterar">
<input type="hidden" name="id" value="<?=$conta["id"]?>" />
<div class="form-group">
<button onclick="msgSucesso()" type="submit" value="Enviar" name="Enviar" class="btn customizado btn-roxo btn-lg">Alterar</button>
</div>
</form>
put by kindness the code that presets the value of this variable $account["id"]
– Julio Henrique
$account = selectIdConta($_POST["id"]);
– veroneseComS
on the change side of your button puts this php code: .. <? php echo $account["id"]; ? > Change</button> if you do not show anything on the side of changing is because your method is wrong
– Julio Henrique
I already know I’ll answer
– Julio Henrique
Appeared "5", is the provider id, should get the account id. Probably there is something wrong in my query? Just can’t find where.
– veroneseComS
is because it spoke reference if * is which table, accounts or person. I’ll put in the answer
– Julio Henrique