I am making a login system and right now I am in the user images part, the problem is that when uploading the image it is uploaded to the corresponding folder and the path is also added to the database, but when trying to print the result with 'echo' nothing is shown and therefore the image is not shown either. I attach part of my code in case someone can help me.
<?php session_start();
$foto = $_SESSION['foto'];
$id = $_SESSION['id'];
include 'php/conexion.php';
$consulta = mysqli_query($link, "SELECT * FROM usuarios WHERE email = '$id'");
$valores = mysqli_fetch_array($consulta);
$nombre = $valores['nombre'];
$email = $valores['email'];
$foto = $valores['foto'];
?>
<span class="image">
<!--aquí es donde deberia cargar la ruta de la imagen, pero no lo hace-->
<img src=<?php ; echo $foto; ?>">
</span>
</div>
<!-- cambiar imagen perfil--->
<div>
<form action="foto.php" method="post" enctype="multipart/form-data">
<input type="text" name="email" value="<?php echo $_SESSION['email'];?>" style=" border: none; display: block;">
<input type="file" name="nfoto">
<button type="submit" class="btn btn-primary">Actualizar</button>
</form>
<!-- cambiar imagen perfil --->
You're getting the user by filtering by
email = '$id'
, so I'm wondering if you actually use email as$id
, or should you filter byid = '$id'
. In any case, you should check if the query actually returns any rows or not. Keeping an eye on the error_log, or activatingdisplay_errors
, would also help you debug.Note .- I have also cast
$id
to integer (int) to make sure that it doesn't screw up the query.