Grab id from the update button

Asked

Viewed 208 times

0

Good afternoon, I’m trying to update a table, inside this table there is a button that saves the bank id, and sends this id to another page, that is this id needs to be used in two functions, I need to take this button id and do an update on this page, I put a form between the <td> from the table and I tried to get the id inside the button to do the update on this page, but I can’t get this id because it is sent to another page, and there it works perfect, but not on this page. Can someone help me?

My code is like this:

//Coloquei o update pra fazer no inicio da pagina
 if((isset($_GET['action'])) AND ($_GET['action']=='gravar')){

 $id = $_POST['id'];

                   $update_query = "UPDATE boletos SET status=1 WHERE id='$id'";
                   mysqli_query($con, $update_query);


}

 <form action='<? echo $PHP_SELF;?>?action=gravar' method="POST"> 
                <tr>                
                  <td><?php echo $row['id']?></td>
                  <td><?php echo $row['categoria']?></td>
                   <td><a href="visualizar.php?id=<?php echo $row['id'] ?>" type="submit" class="btn btn-primary" target="_blank">Visualizar</a></td>
   //Aqui ele pega o id do banco e abre outra pagina visualizar,
//mas eu precisava usar esse id também nesta mesma pagina pra fazer o update
</form>
  • Important you [Dit] your post and explain in detail the problem, describing what you tried and where is the current difficulty, preferably with a [mcve] of the problematic code. Studying the post available on this link can make a very positive difference in your use of the site: Stack Overflow Survival Guide in English

1 answer

0


So when loading you can bring the id to send via POST as you wanted in your update, just add and update the id, OBS: Pick the name the value of the input meu_id.

input type="Hidden" id="pegaid" name="meu_id" value="echo $Row['id']>"

  • Thanks @Pedro Ortriz, you saved my life, was killing me here kkk worked perfectly, thank you, God bless you.

  • Cooooding lets! <3

Browser other questions tagged

You are not signed in. Login or sign up in order to post.