PHP를 사용하여 간단한 CRUD를 만들었지 만 홈 파일은 다른 사용자가 추가 한 정보까지 데이터베이스에있는 모든 정보를 표시합니다. 어떻게 로그 된 사용자 정보 만 표시하도록 필터링 할 수 있습니까? 당신이 $_SESSION['user']
또한 세션에 사용자 레코드 ID를 할당 할당하는 곳마다모든 사용자 정보를 표시하는 홈
<?php
session_start();
if(isset($_SESSION['user'])){
echo "Logado como ". $_SESSION['user'];
}
else {
echo"<script language='javascript' type='text/javascript'>alert('Voce deve estar logado');window.location.href='index.php';</script>";
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Perfil</title>
</head>
<body>
</br>
<a href="logout.php">Sair</a></br>
<h2 align="center">Lista de contatos</h2>
<table align="center" border="1">
<tr>
<th>Nome</th>
<th>Telefone</th>
<th>Endereco</th>
<th>Editar</th>
<th>Deletar</th>
</tr>
<?php
mysql_connect("localhost", "root","") or die(mysql_error()); //Connect to server
mysql_select_db("forms") or die("Cannot connect to database"); //connect to database
$query = mysql_query("Select * from contatos"); // SQL Query
while($row = mysql_fetch_array($query))
{
Print "<tr>";
Print '<td align="center">'. $row['nome'] . "</td>";
Print '<td align="center">'. $row['telefone'] . "</td>";
Print '<td align="center">'. $row['endereco'] . "</td>";
Print '<td align="center"><a href="editar.php?id='. $row['id'] .'">Editar</a> </td>';
Print '<td align="center"><a href="deletar.php?id='. $row['id'] .'">Deletar</a> </td>';
Print "</tr>";
}
?>
</table>
<div align="center">
<a href="informacoes.php">Adicionar contato</a></br>
</div>
</body>
</html>
미안하지만, 이것은 많은 도움이되었습니다. 유용하다고 생각하시면 –
감사합니다. 답변으로 인정하실 수 있습니다. –