PHP and Mysql session

Asked

Viewed 86 times

3

I have two tables one for login and password and another where are the user data, as address, phone, etc..

After logging in would that the data displayed on the screen were not the login and yes the name of the person, with telephone address.

The session code is this, I’m using two table 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");
}
?>

1 answer

5

You need to make a 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 put in session:

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

Browser other questions tagged

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