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

Asked

Viewed 1,227 times

0

Hello guys I’m doing a test, and I have the data in a table in my index page in HTML and I intend to click a button in front of some data and then forward me to another page that will show the name of the person I clicked and insert phones in the other table that I have.

Initially I don’t know how to get the name of the person I click to use the page additel.php, someone 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>

  • You can pass on the link like this adicionatel.php?id=<?php echo $id; ?> ai on the page adicionatel.php you search the person’s data by id.

3 answers

1

On your link put like this

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

On your additel.php page put it like this...

<?php

echo $_GET['id'] . ' - ' . $_GET['nome'];
  • Thanks guys helped me and solved my problem! :D

  • if you can mark as correct the answer I thank you. thank you =)

  • How do I mark as correct?

  • has a little checkup below the dots..

  • I couldn’t find... :(

  • it must be because you are not registered user, but everything well is quiet ;)

Show 1 more comment

1

You can pass to String nomee by get will stay like this.

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

on your screen additel.php

you get this String thus:

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

1

Going through everything by get is not the best option, you have to pass only the ID and on the page insert the data you consult the record to know if it exists, if not, you can display some error message, in this case would be like this:

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

and additel.php :

$selbanco = "SELECT * FROM pessoa WHERE id = " . $_GET['id'];

Browser other questions tagged

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