I have the following functions: Archive registra_conta.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 noticed that if I change '$ id_to_selected' by an id registered in the database, the query works, however, through the POST method I can not get the account id.
File alter_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>