Get the id from a list of the database, and use on another page to insert phones in PHP

1
Hello everyone, I'm doing a test, and I have the data in a table in my HTML index page and I want to click on a button in front of some data and then go to another page that shows the name of the person that I clicked and insert phones on the other table that I have.

Initially, I do not know how to get the name of the person I clicked to use in the add-on.php page, somebody help me. Thank you.

<table id="test" class="text-center">
                    <caption>Dados da Tabela Pessoa</caption>
                    <tr><td><h4>ID</h4></td><td><h4>Nome</h4></td><td><h4>CPF</h4></td></tr>
                    <?php
                    
                    $selbanco = "SELECT * FROM pessoa";
                    $querybanc = mysql_query($selbanco);
                    
                    //$conta = mysql_num_rows($querybanc); //essa funçao conta quantas linhas tem na tabela do banco
                    
                    while ($linha = mysql_fetch_array($querybanc)){
                        
                        $id = $linha['id'];
                        $nomee = $linha['nome'];
                        $cpff = $linha['cpf'];
                        
                        //echo "$id $nomee $cpff <br>";
                ?>
                    <tr><td><?php echo "$id"; ?></td><td><?php echo "$nomee"; ?></td><td><?php echo "$cpff"; ?></td>
                        <td><a href="adicionatel.php" class="btn btn-success">Adicionar telefone de contato</a><?php } ?></td></tr>
                </table>
    
asked by anonymous 08.09.2016 / 16:12

3 answers

1

You can move to String nomee because get will stay like this.

<a href="adicionatel.php?nome=<?php echo $nomee;?>" class="btn btn-success">Adicionar telefone de contato</a>

on your add-on.php screen

You get this String like this:

$nome=$_GET['nome'];
//e vc pode utilizar a variavel como quiser por ex faz um echo
echo $nome;
    
08.09.2016 / 16:18
1

Passing everything by get is not the best option, you have to pass only the ID and in the page of inserting the data you consult the registry to know if it exists, if not, you can display some error message, in this case would look like this:

<a href="adicionatel.php?id=<?=$id?>" class="btn btn-success">Adicionar telefone de contato</a>

and in the addin.php:

$selbanco = "SELECT * FROM pessoa WHERE id = " . $_GET['id'];
    
08.09.2016 / 16:30
0

In your link put it like this

<a href="adicionatel.php?id=<?=$id?>&nome=<?=$nome?>" class="btn btn-success">Adicionar telefone de contato</a>

On your page addname.php so put ...

<?php

echo $_GET['id'] . ' - ' . $_GET['nome'];
    
08.09.2016 / 16:16