2
On the login screen I make the query to free the access to the system, after that I would like to make a complete query of the data of that user and to write in the SESSION.
<?php
// inclui o arquivo de inicialização
require 'init.php';
// resgata variáveis do formulário
$email = isset( $_POST[ 'email' ] ) ? $_POST[ 'email' ] : '';
$telefone = isset( $_POST[ 'telefone' ] ) ? $_POST[ 'telefone' ] : '';
if ( empty( $email ) || empty( $telefone ) ) {
echo "Informe Email e Senha corretamente.";
exit;
}
// cria o hash da senha
$telefoneHash = make_hash( $telefone );
$PDO = db_connect();
$sql = "SELECT id, name AND email FROM users WHERE email = :email AND telefone = :telefone ";
$stmt = $PDO->prepare( $sql );
$stmt->bindParam( ':email', $email );
$stmt->bindParam( ':telefone', $telefoneHash );
$stmt->execute();
$users = $stmt->fetchAll( PDO::FETCH_ASSOC );
if ( count( $users ) <= 0 ) {
echo "Email ou Senha incorretos";
exit;
}
// pega o primeiro usuário
$user = $users[ 0 ];
session_start();
$_SESSION[ 'logged_in' ] = true;
$_SESSION[ 'user_id' ] = $user[ 'id' ];
$_SESSION[ 'user_name' ] = $user[ 'name' ];
//AQUI É QUE PRECISO PREENCHER
//$_SESSION['user_endereco'] = $variavelbanco;
//$_SESSION['user_numero'] = $variavel2banco;
?>
Did I understand if you want to record your table data in a Session? if that’s why?
– novic
That’s right, I actually think I’m going to switch from Session to localStorage, is that I already have some data there as the user name, what I don’t understand is about the query and putting the data into variables. I researched a lot but I do not understand anything of connection with the bank, nothing comes out.
– Hugo Nascimento
So if you need to stop and start from scratch (it’s a tip don’t get me wrong) because localStorage is something else ... !!!!
– novic
You can use json_encode and then save both in Session and Localstorage. Ps.: Depending on the goal, it is not the best option.
– Valdeir Psr
I’m using it, few user information that are Session, the shopping cart and other information are on locationStorage.
– Hugo Nascimento
Yes, my problem lies more on the part of bringing the database data and passing it to variables
– Hugo Nascimento
This information (which you want to add to the address and number sessions) is in the users table?
– Andrei Coelho
Yes, I need to get this information:
name
email
telefone
endereco
numero
bairro
cidade
– Hugo Nascimento
@Hugonascement use "@" to signal someone. Thus, the comment appears in the box of the person you are talking to. =)
– Andrei Coelho