Pass data through the link - php application

Asked

Viewed 1,131 times

1

People I’m not able to do something, I’m beginner in php and web programming and I’m trying to make a page to receive the ID of any user through a click on the link:

  `while($linha = mysqli_fetch_array($result) ) {

                            $id_usuario = $linha['ID_usuario'];
                            $name = $linha['nome'];
                            $Sexo= $linha['sexo']; 

                            echo "<tr> <td><a href='#'>$id_usuario</a></td> <td>$name</td> <td>$Sexo</td> <td>Tipo</td> </tr>"; //falta definir a pagina


                                    }`

It’s a simple procedure I believe, on the other page I’d like you to take the user id and do a Select in all the information of this user registered at the bank, but I want to know how I could do it on this other page

  • Number one: NEVER USE GET TO PASS USER AND PASSWORD. Second, take a look here in the same Stack, there are HUNDREDS of login examples using PDO, which is currently the most secure. Here’s a great example: http://blog.thiagobelem.net/como-crea-um-system-de-login-niveis-permissao

  • 1

    Thank you Diego, I’ve already studied it

  • 2

    @Diego PDO is no safer than mysqli. Using it right, mysqli is even safer, because the PDO by default simulates the Prepared statements, different from the mysqli that makes native. The only "advantage" that PDO has that makes it easier to exchange DB, which usually only makes sense in larger libraries (and even then, if the library is well optimized, it will give preference to native Enginers).

  • @Bacco, my bad. I gave a personal opinion on security, without technical basis. Thank you for the clarification.

  • @Diego Remembering that both lend themselves well to the service, I just didn’t want to leave the poor mysqli taking bad fame to some kkk

1 answer

0


First you should pass the id through the link:

 echo "<tr> <td><a href='dados.php?id=".$id_usuario."'>$id_usuario</a></td> <td>$name</td> <td>$Sexo</td> <td>Tipo</td> </tr>";

On the other page you need to make a query to the database picking up the id:

<?php
// retirado de codigosnaweb.com - scripts grátis para o seu site

// PODE SER SEPARADO O TRECHO ABAIXO PARA SER CHAMADO POR INCLUDE
define("SERVIDOR", "<endereço do servidor de banco de dados>");
define("USUARIO", ",<usuário>");
define("SENHA", "<senha>");
define("BANCODEDADOS", ",<nome do banco de dados>");
$conecta = new mysqli(SERVIDOR, USUARIO, SENHA, BANCODEDADOS); // CONECTA

if ($conecta->connect_error) {
    trigger_error("ERRO NA CONEXÃO: "  . $conecta->connect_error, E_USER_ERROR);
}
// PODE SER SEPARADO O TRECHO ACIMA PARA SER CHAMADO POR INCLUDE

$sql = "$sql = "SELECT * FROM suatabela WHERE id=".$_GET['id']."";"; // CONSULTA
$query = $conecta->query($sql); // RODA A CONSULTA
$linhas = $query->num_rows;
if($linhas >= 1) { // SE HÁ LINHAS
    while($colunas = $query->fetch_assoc()) {
        echo " {$colunas["texto"]} "; // DADOS DA CONSULTA
    }
    $query->free(); // LIBERANDO OS DADOS DA CONSULTA
} else {
    echo "Não há resultados"; // SEM RESULTADOS
}
$conecta->close(); // FECHANDO A CONEXÃO
?>

Replace your database information (name, address, user and password) in this code and save in a "data.php file".

Browser other questions tagged

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