How can I use $ _SESSION?

0

I have this error "Notice: Undefined variable: user in C: \ xampp \ htdocs \ html \ index2.php on line 9"

<?php
    $user = $_POST['user'];
    $pass = $_POST['pass'];
    $impr = $_SESSION['user'] = "$user";

    //conectar a la base de datos
    $conexion = mysqli_connect("localhost","root","","login");
    $consulta = "SELECT * FROM usuarios WHERE user='$user' AND pass='$pass'";
    $resultado = mysqli_query($conexion,$consulta);

    $filas = mysqli_num_rows($resultado);
    if ($filas > 0) {
        header("location:index2.php");
    } else {
        echo "NO SE A ENCONTRADO NINGUN DATO";
        echo "POR FAVOR VERIFICA TUS DATOS";
    }
    mysqli_free_result($resultado);
    mysqli_close($conexion);
?>
    
asked by LUIS GERARDO CONTRERAS MATIAS 25.11.2018 в 20:22
source

2 answers

1

Apart from the problem that you pose, to keep the session data in each file, the first thing you should do as soon as you open the keys is a session_start (). I mean:

<?php
session_start();
...
    
answered by 26.11.2018 в 00:13
0

In the HTML%% co, make sure the <form> is correct and also that the action is method .

    
answered by 25.11.2018 в 22:29