I'm doing a login with SESSION and I don't understand why I get the error: Notice: Undefined index: user in C:\xampp\htdocs\Projecte\patients.php on line 3
and then at the bottom of Welcome I don't see the user who is logged in and I don't understand what could be happening. If someone can help me I will be very grateful since I am doing a project with PHP and I haven't finished the SESSION issue fully understand
I'll pass you the code I have:
<?php
session_start();
$varsesion=$_SESSION['usuario'];
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="estils.css">
<link rel="icon" type="image/ico" href="favicon.ico">
<title>Pràctica M09-UF1</title>
</head>
<body>
<h1>Bienvenido : <?php echo $varsesion ?> </h1>
<a href='cerrarsesion.php'>Cerrar Sesión</a>
<div id="container">
<div id="color">
<div id="fotologo">
<img src=img/fhes.png>
</div>
</div>
<ul>
<li><a href="#section1">Inici</a></li>
<li><a href="#section2">Qui som?</a></li>
<li><a href="#section3">Historia</a></li>
<div class="dropdown">
<button class="dropbtn">Serveis
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a href="#">Ginecologia</a>
<a href="#">Consultes Externes</a>
<a href="#">Traumatologia</a>
<a href="#">Cirugia</a>
<a href="#">Medicina Interna</a>
<a href="#">Urgencies</a>
<a href="#">Quiròfan</a>
</div>
</div>
<li><a href="#section5">Consultes</a></li>
<li><a href="#section6">Contacte</a></li>
</ul>
<form action="crear.php" method="post">
<input type="text" placeholder="Nombre" name="in_name">
<input type="text" placeholder="Apellido" name="in_cognom">
<input type="text" placeholder="Dia Ingreso" name="in_dingres">
<input type="text" placeholder="Motivo" name="in_motiu">
<input type="submit" name="in_bot">
In the code where the login is done on your page I think you may have forgotten to define this variable. Namely:
If the query returns a result, it means that the user exists and has entered the password correctly, then you redirect him to the page you want (I guess to "patients.php"), but before that you must define that variable. That is, something like this: