I am making a validation in the Login and I get this error
Notice: Undefined variable: connection in C: \ xampp \ htdocs \ Inventory Infrastructure \ php \ validar.php on line 14
Fatal error: Uncaught Error: Call to a member function prepare () on null in C: \ xampp \ htdocs \ Inventory Infrastructure \ php \ validar.php: 14 Stack trace: # 0 {main} thrown in C: \ xampp \ htdocs \ Inventory Infrastructure \ php \ validar.php on line 14
Someone can help me, I'm just starting with PHP programming and it's the first time I've faced this. I leave the source code.
session_start();
if(isset($_SESSION['usuario'])){
header('location: ../index.php');
}
if ($_SERVER['REQUEST_METHOD']=='POST') {
$usuario = $_POST['user'];
$password = $_POST['pass'];
require('conexion.php');
$consulta = $conexion -> prepare('SELECT * FROM usuarios WHERE Nombre_Usuario= :user AND Contrasena= :pass');
$consulta ->execute(array(':user'=>$usuario, ':pass'=>$password));
$resultado = $consulta -> fecth();
if($resultado!==false){
$_SESSION['usuario'] = $usuario;
header('location: index.php');
}else{
header('location: login.php');
}
}
Thanks