error when printing the data of a logged in user ..!

0

Sorry for the inconvenience, but I have a great doubt, I get an error when showing the data of the logged in user, the strange thing is that if you allow me to enter the moment I enter the username and password.

I have a file login.php .

<?php
  require_once("clase/conexion.php");
  if(
    isset($_REQUEST["user"]) &&
    isset($_REQUEST["pass"])
    ){

    $query = $mysqli->query("
      SELECT * FROM admin 
        WHERE usuario = '".$_REQUEST["user"]."'AND 
              password = '".$_REQUEST["pass"]."'
      ");
    $con = $query->fetch_assoc();

    if(
      $_REQUEST["user"] == $con["usuario"] &&
      $_REQUEST["pass"] == $con["password"]
      ){
        session_start();
        $_SESSION["user"] = $con["usuario"];
        $_SESSION["pass"] = $con["password"];

        header("Location: inicio.php");
        }
    }
?>

and a view where I print the name of the user that is logged in home.php

<?php echo $_SESSION["usuario"]; ?>

and I get this error, telling me that in the view where I print the user's name is undefined which would be $ _ SESSION ["user"] .

Undefined index: user in C: \ wamp64 \ www ..

    
asked by Anthony 13.11.2016 в 06:07
source

1 answer

0

man yourself you show the error and the solution, you want to print a session fix with the index 'usuario' when you are declaring one with the fix index of the same as 'user' in your login.php

remember that when doing:

$_SESSION["user"] = $con["usuario"];

the index of the fix $con does not become the index of the fix $_SESSION

The solution is to change in:

<?php echo $_SESSION["usuario"]; ?>

By:

<?php echo $_SESSION["user"]; ?>
    
answered by 13.11.2016 / 10:45
source