Hello friends, I am currently trying to migrate this profile code from session to pdo but it gives me errors.
The situation is the following if I start session and I want to modify my profile data but as I said, it shows me an error and I did a var_dump
and it throws me the following:
array (11) {["idUser"] = > string (2) "12" ["loginUsers"] = > string (9) "userNtest" ["nameProfi"] = > string (8) "Standard" ["idProfile"] = > string (1) "2" ["id"] = > NULL ["mail"] = > NULL ["idnivel"] = > string (13) "Administrator" ["Administrator"] = > string (12) "Yoclens2016-" ["names"] = > string (1) "" ["user"] = > NULL ["password"] = > NULL}
Attach the full code to see where this is failing:
FIRST:
file to validate the sessions:
Preparamos la consulta y la ejecutamos
$sql = $DB_con->prepare('SELECT * FROM usuarios WHERE user = :user AND
password = :password AND idnivel = \'Administrador\' LIMIT 1');
$sql->bindParam(':user', $_POST['user']);
$sql->bindParam(':password', hash('sha256', $_POST['password']));
$sql->execute();
$sql->closeCursor();
// Comprobamos si ha devuelto algun registro
if($sql->rowCount()){
// Iniciamos sesion
session_start();
// Recuperamos los datos de la consulta
$row = $sql->fetch(PDO::FETCH_ASSOC);
//definimos las variables necesarias para la sesion
$_SESSION['id'] = $id;
$_SESSION['user'] = $user;
$_SESSION['password'] = $password;
$_SESSION['idnivel'] = 'Administrador';
$_SESSION['cedula'] = $cedula;
$_SESSION['nombres'] = $row['nombres'].' ' .$row['apellidos'];
$_SESSION['email'] = $email;
$_SESSION['telefono'] = $telefono;
$_SESSION['direccion'] = $direccion;
// Redirigimos la pagina
header("Location: admin/home.php");
exit;
now believe that it is okay to define the variables necessary for the session? After that, I start session now once the session has started, what I want is to change the profile data of that user who has the session started, but I do not load any value the fields show them in blank, this abalo file is for change the profile data of the user that would be my profile.php, but as I said before, only the blank fields are shown
<!-- la session-->
<?php
session_start();
if(!isset($_SESSION['Administrador']))
{
header('Location: ../index.php?Error=Acceso denegado');
echo "<script>alert('Disculpe Acceso registringido, Usuario no Autorizado')</script>";
exit();
}
?>
<!-- fin de la session-->
introducir el código aquí<!-- proceso para consultar-->
<?php
var_dump($_SESSION);
$user=$_SESSION['user'];
$password=$_SESSION['password'];
$perfil = $DB_con->prepare("SELECT * FROM usuarios WHERE user = :user AND password = :password");
$perfil->bindParam(':user',$_SESSION['user']);
$perfil->bindParam(':password',$_SESSION['password']);
$perfil->execute();
$editar_linea = $perfil->fetch(PDO::FETCH_ASSOC);{
?>
<!-- fin proceso para consultar-->
<!-- para mostrar los datos-->
value='<?php echo $editar_linea['cedula'];?>'
<!-- fin para mostrar los datos-->