PHP and MySql Session

3

I have two tables, one for login and password, and one for user data such as address, phone, etc.

After signing in I would like the data displayed on the screen not to be the login, but the person's name, with a telephone address.

The session code is this, I'm using two tables in mysql.

session_start();
$message="";
if(count($_POST)>0) {
    $conn = mysql_connect("localhost","root","");
    mysql_select_db("users",$conn);
    $result = mysql_query("SELECT * FROM users WHERE user_name='" .      
    $_POST["user_name"] . "' and password = '". $_POST["password"]."'");
    $row  = mysql_fetch_array($result);
    if(is_array($row)) {
         $_SESSION["user_id"] = $row[user_id];
         $_SESSION["user_name"] = $row[user_name];
    } else {
         $message = "Login e Senha Invalidos!";
    }
}
if(isset($_SESSION["user_id"])) {
     header("Location:painelcontrol.php");
}
?>
    
asked by anonymous 21.08.2015 / 13:25

1 answer

5

You need to Inner Join to select the data from the other table taking into account the user code.

SELECT 
   LOGIN, 
   EMAIL, 
   SENHA, 
   NOME, 
   ENDEREÇO, 
   TELEFONE 
FROM 
   USERS
INNER JOIN
   USERS_ENDERECO ON USERS_ENDERECO.ID_USER = USERS.ID_USER
WHERE
   EMAIL = '$email'
AND
   SENHA = '$senha'

After that, just log in:

$_SESSION["ENDERECO"] = $row[endereco];

    
21.08.2015 / 13:34