0
Good afternoon, I’m early in php and would need a help.
I have this file (index.php) where I want to show the name of the logged in user on the screen after his login, however this giving an undefined variable error ( $_SESSION).
Note: Disregard the last div=main line
$usuario = $_SESSION['usuarioSession'];
$senha = $_SESSION['senhaSession'];
$sql = mysql_query("SELECT * FROM syslogin WHERE usuario = '$usuario' AND senha = '$senha'");
while($linha = mysql_fetch_array($sql)){
$usuario = $linha['usuario'];
$senha = $linha['senha'];
}
?>
<div class="bemvindo">Bem Vindo! <strong><?php echo $usuario;?></strong> | Hoje é: <?php echo date('d/m/Y');?></div><!--Bem Vindo-->
<div id="principal">
<h3>Bem Vindo(a).</h3><br /><br />
<img src="css/img/logo1.jpg" alt="logo" />
</div> <!-- Fim da div#principal -->
<?php include('includes/fimerodape.php'); ?>
Please where I’m going wrong?
That code you put out is the whole page? Remember that to work with SESSION you need to initialize it: session_start(); at the beginning of the page.
– Bsalvo
Be careful that the code you are using does not protect you against attacks from mysql Injection. At least pass inputs through the function mysql_real_escape_string. And consider switching to mysqli or Prepared statements
– Isac