PHP - SQL: display the user's email through the database

-1

Galera, is as follows: Having made the user's registration on the site, it saves it in the database (obvious).

This is the code for connecting to the database (is that correct?):

<?php      
echo $sql= "select *  from users order by email";
$rs =mysql_query($sql,$connection) or die ("Consulta nao realizada");
?>

The question is how to get the bank to just pick up the active user's email and not show the email of all users of the site.

I want to show the active user's email with an "echo $ email" and I do not know where and how to appear.

Thank you!

    
asked by anonymous 13.07.2016 / 22:18

2 answers

0

I recommend using PDO , the native functions of MySQL for PHP are decapitated for years.

But answering your question, you do not need the second parameter. Considering that a connection to the database is open just use

$query = mysql_query('select *  from users order by email');

And to return the data simply use the mysql_fetch_assoc

while ($row = mysql_fetch_assoc($query)) {
    echo $row["userid"];
    echo $row["fullname"];
    echo $row["userstatus"];
}

I recommend reading the complete mysql_query documentation clicking here .

    
13.07.2016 / 22:24
0

I recommend using sessions you will have to do the Mysql query by filtering the id of the user that logged in.

$sql = "Select email from users where id = $id"; //id = a chave primária da tabela de usuarios
$query = @mysql_query($sql);
$resultado = @mysql_fetch_assoc($query);

This is done now to create the session and define its value

$_SESSION['usuarioID'] = $resultado['id']; //exemplo de outros dados que queira
$_SESSION['usuarioEmail'] = $resultado['email'];

to show email

$pEmail = $_SESSION['email']; 

echo $pEmail;
    
15.07.2016 / 05:34