How to view user data on a page through ID?

Asked

Viewed 216 times

0

I am developing a website where the administrator can view the registration data of all users who are registered in the system, and this data is displayed in a table. The table only displays some data (id, name and email) and I want to make a link where the administrator can click to see the complete information of the selected user. For example, if he clicks on the "see more" link of the user with ID 1, the screen displays all his data (id, name, rg, Cpf, email, date of birth).

My code for now is this:

<?php 
    $consulta = "SELECT * FROM adms";
    $con = mysqli_query($con, $consulta) or die (mysqli_error);
?>
<table border="1" cellpadding="25px;">
    <tr>
        <td>ID</td>
        <td>Nome</td>
        <td>E-mail</td>
        <td></td>           
    </tr>
    <?php while($dado = $con->fetch_array()){ ?>
        <tr>
            <td><?php echo $dado['id'] ?></td>
            <td><?php echo $dado['nome'] ?></td>
            <td><?php echo $dado['email'] ?></td>
            <td><a href="adm_vermaisAdm.php?id='$dado[id]'">Ver mais</a></td>
        </tr>
    <?php } ?>
</table>

The table looks like this:

Tabela que mostra dados de todos os administradores cadastrados

My main doubts are:

1) The line <a href="adm_vermaisAdm.php?id='$dado[id]'">Ver mais</a> is stated the right way? I am in doubt because of the $given[id], I don’t know if it will work this way

2) To create the data display page, its name would be adm_vermaisAdm.php? id='$given[id]' ?

3) To display this data, how do I get the URL ID?

From now on I thank everyone who answers

1 answer

0


Whoa! All right? I think I can help you. In the order of doubt:

First doubt

The way it is written will not work. Remember that the tag <a> is HTML and that to interpolate php data in your declaration, you must again open the php tag. Follow example:

<a href="adm_vermaisAdm.php?id='<?php echo $dado['id']?>'">Ver mais</a>

This will already ensure that your anchor is pointing to the "adm_vermaisAdm.php" page, passing in the url the id parameter, with value equal to that stored in the $given ['id'].

Second doubt

The answer is no! The page (php file) you are pointing to at the anchor is "adm_vermaisAdm.php" and this is how the file should be named.

adm_vermaisAdm.php

Third doubt

To get the id that came through your URL, you can do the following:

<?php $id = $_GET['id']; ?> 

So you will already have in hand the id to perform the query on and display all the data relating to it.

I hope I helped :D!

  • Thank you very much! I managed to display the data without problems :)

Browser other questions tagged

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