Good, some way to show the data of a logged in user?
I need that after a user logs in, in another page show me the data of this user:
I have two tables:
And this is my code with which I am validating and trying to extract the user's data.
<?php
require_once('conexion.php');
session_start();
if (isset($_POST["submit"])) {
$usuario=$_POST["nusuario"];
$contrasena=$_POST["ncontrasena"];
$usuario = stripslashes($usuario);
$usuario = mysql_real_escape_string($usuario);
$contrasena = stripslashes($contrasena);
$contrasena = mysql_real_escape_string($contrasena);
$id_emp="";
$sql="SELECT * FROM usuario WHERE usuario='$usuario' AND (contrasena='$contrasena' AND estado='Activo') ";
$result = $conn->query($sql);
if ($result->num_rows == 1) {
while($row = $result->fetch_assoc()) {
$id_emp=$row["id_empleado"];
}
$_SESSION['iduser']=$usuario;
$sql2="SELECT * FROM empleado WHERE id_empleado='$id_emp'";
$result2=$conn->query($sql2);
if ($result2->num_rows == 1) {
while($row = $result->fetch_assoc()) {
$_SESSION["nombre"]=$row["nombre"];
$_SESSION["apellidos"]=$row["apellidos"];
$_SESSION["tipo"]=$row["tipo"];
$_SESSION["dni"]=$row["dni"];
$_SESSION["ubicacion"]=$row["ubicacion"];
$_SESSION["telfmovil"]=$row["telfmovil"];
$_SESSION["email"]=$row["imagen"];
}
// header("Location: ../venta_venta.php");
}
// if($row = mysql_fetch_array($execute)){
// }
// $_SESSION['username'] = $username;
$mensaje = "¡Bienvenido al Sistema!";
echo "<script type='text/javascript'>alert('$mensaje');</script>";
header( "refresh:0.2;url=../venta_venta.php" );
}else{
$mensaje = "Error! La contraseña o usuario ingresado son incorrectos";
echo "<script type='text/javascript'>alert('$mensaje');</script>";
header( "refresh:0.2;url=../login_agro.php" );
}
}
$conn->close();
?>
As you can see in the code, I extract the data from my used table and store it in those variables $ _SESSION []. But now I want to show those values stored on another page called mantencion_cuenta:
<?php
require_once('verifica.php');
?>
<div class="form-group">
<label for="idnombre">Nombre:</label>
<input type="text" REQUIRED disabled class="form-control" id="idnombre" value="<?php echo $_SESSION['nombre']; ?>">
</div>
And the error that you send me is the following:
<br /><b>Notice</b>: Undefined index: nombre in <b>C:\xampp\htdocs\PROYECTO_WEB\mantenimiento_cuenta.php</b> on line <b>178</b><br />
And I do not understand why. Any idea how to fix it? Thanks in advance.