When I write a comment the email of all registered people appears. How do I only show my email that was logged in?

Asked

Viewed 49 times

0

That is the code:

<?php

$conexao = mysqli_connect("localhost", "root", "");
mysqli_select_db($conexao, "videoaula");

?>

<?php

$sql = "select comentarios.id, comentarios.comentario, usuarios.email from comentarios, usuarios order by id desc";
$executar = mysqli_query ($conexao, $sql);
while ($exibir = mysqli_fetch_array ($executar)){;

echo "<strong>ID:</strong>".$exibir ["email"];
echo "<br/>";
echo "<strong>Comentário:</strong>".$exibir ["comentario"];
echo "<br/><br /><br />";
}

?>

When I execute the code, appears all registered emails, as below:

ID:thaina123
Comentário:olá mundo!!


ID:[email protected]
Comentário:olá mundo!!


ID:[email protected]
Comentário:olá mundo!!


ID:[email protected]
Comentário:olá mundo!!

1 answer

0


You must save the user id in the comments table, and turn it on Where as below:

select 
  comentarios.id, 
  comentarios.comentario, 
  usuarios.email 
from comentarios, usuarios
  where comentarios.idusuario = usuarios.id
order by id desc
  • Hello, thank you for your reply! But how do I save user id in comment table?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.