I can not retrieve the id value through the POST method

0

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>

Why am I unable to recover the account id?

    
asked by anonymous 29.01.2018 / 20:24

1 answer

1

The problem is in your select query.

change this:

SELECT * FROM contas c INNER JOIN pessoa p ON(c.id_fornecedor = p.id) WHERE c.id = ".$id

for this:

SELECT c.* FROM contas c INNER JOIN pessoa p ON(c.id_fornecedor = p.id) WHERE c.id = ".$id

As you said in the comments, the vendor id 5 is appearing and does not have accounts with that id.

    
29.01.2018 / 20:48