简体   繁体   English

如何生成编码以仅显示用户在个人资料中发布的内容

[英]How can I generate coding to only display what the user has posted in their profile

Within the user profile I am trying to only allow the user to see what they have posted to the database but with the coding this way it shows everything from the database in every users account. 在用户个人资料中,我试图仅允许用户查看他们发布到数据库的内容,但是通过这种编码方式,它可以显示每个用户帐户中数据库的所有内容。 How can I get it to only echo what the user has created. 我如何才能只回显用户创建的内容。

<?php 

include("headers.php");

if($_POST['delete']) {
$title=$_POST['title'];
echo $title;
$result = mysql_query("DELETE FROM test2 where fname='$title'");

if($result)
echo "<div style='color:red;'>The ".$row['fname']." datas are deleted successfully.<br>   <br></div>";
}


if($_POST['submit']) { 

$title=$_POST['title'];
$result = mysql_query("SELECT * FROM test2 where fname='$title'");

$row = mysql_fetch_assoc($result);
 @$image=$row ['photo'];
  echo "<div style='width: 600px;border: 1px solid black;padding: 30px;float:     center;text-align: center;margin: auto;margin-top: 140px;'>  <span style=' font-size: 20px;      font-weight: bold;'>Recent Post</span><br><br>
  <table style='width:100%;border-bottom:1px solid gray;'><tr><td><table style='width:90%;'><tr><td>Name:</td><td>".$row['fname']."</td></tr>
  <tr><td>Start Date:</td><td>".$row['stdate']."</td></tr>
  <tr><td>End Date:</td><td>".$row['endate']."</td></tr>
  <tr><td>Address:</td><td>".$row['addr1']."</td></tr>
  <tr><td></td><td>".$row['addr2']."</td></tr>
  <tr><td></td><td>".$row['city']."</td></tr>
  <tr><td></td><td>".$row['state']."-".$row['zip']."</td></tr>
  <tr><td>Description:</td><td>".$row['description']."</td></tr>

  <tr><td>Link:</td><td><a href=".$row['link'].">".$row['link']."</a></td></tr>
  </table></td><td><img src='image/".$image."' alt='image'  style='width:100px;height:100px;'></td></tr></table><br/><br/><a href='index.php'>Go Back To Home </a></div>";

 // echo "<div style='width:90%;float:center;border-bottom:1px solid blue;'></div>";
  }  else {
$result = mysql_query("SELECT * FROM test2");
echo "<div style='width: 600px;border: 1px solid black;padding: 30px;float: center;text-align: center;margin: auto;margin-top: 140px;'>  <span style=' font-size: 20px;    font-weight: bold;'>Recent Post</span><br><br>";
while($row = mysql_fetch_array($result))
{
 @$image=$row ['photo'];
  echo "<table  style='width:100%;border-bottom:1px solid gray;'><tr><td><table style='width:90%;'><tr><td>Name:</td><td>".$row['fname']."</td></tr>
 <tr><td>Start Date:</td><td>".$row['stdate']."</td></tr>
 <tr><td>End Date:</td><td>".$row['endate']."</td></tr>
 <tr><td>Address:</td><td>".$row['addr1']."</td></tr>
 <tr><td></td><td>".$row['addr2']."</td></tr>
 <tr><td></td><td>".$row['city']."</td></tr>
 <tr><td></td><td>".$row['state']."-".$row['zip']."</td></tr>
 <tr><td>Description:</td><td>".$row['description']."</td></tr>

 <tr><td>Link:</td><td><a href=".$row['link'].">".$row['link']."</a></td></tr>
 </table></td><td><img src='image/".$image."' alt='image' style='width:100px;height:100px;'></td></tr></table>";
}
  echo "<br/><a href='index.php'>Go Back To Home </a></div>";

  }

 ?>

It is uncertain but if you keep identity of user in session or in users profile you already know the identity of user so we can assume to get the identity of user through $_SESSION['userid'] , $_GET['userid'] or $_POST['userid'] . 不确定,但是如果您在会话中或用户个人资料中保留用户身份,则您已经知道用户身份,因此我们可以假设通过$ _SESSION ['userid']$ _GET ['userid']$ _POST ['userid']

$userId = $_SESSION['userid'];

OR 要么

$userId = $_GET['userid'];

whatever, you have to have user information to query from database. 无论如何,您必须具有用户信息才能从数据库中查询。 It can be user name or any info of an user instead of userid 它可以是用户名或用户的任何信息,而不是userid

$result = mysql_query("SELECT * FROM test2 where fname='$title' AND userid ='$userId'");

Also, you should have a look at preventing SQL Injection 另外,您应该看看防止SQL注入

Your question lacks a lot of information (such as your database schema). 您的问题缺少很多信息(例如您的数据库架构)。 But you will probably just need a WHERE clause in your SQL which you specify the user. 但是您可能只需要在SQL中指定用户的WHERE子句即可。 For example, 例如,

SELECT * FROM test2 WHERE fname='$title' and user=$userid

Or something of the like, depending on the schema. 或类似的东西,取决于模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何仅显示发布评论的用户的删除和编辑链接? - How do I show the delete and edit links only to the user who has posted the comment? 如何在查看 Laravel 时显示用户个人资料图片 - How I can display user profile picture on view laravel 如何将/ profile?user = user更改为profile / user - How I can change /profile?user=user to profile/user 我怎么知道我在php中发布的价值是什么? - How can I know what are the value I have posted in php? 我如何检索发布帖子的用户 - How can i retreive the user who posted the post 如何显示已预订用户的电子邮件 - How can I display the email of the user who has booked PHP/MySQL:在投票系统中,如何防止用户看到他已经投票的个人资料? - PHP/MySQL: In a Voting System, how can I keep a user from seeing a profile he has already voted on? 如何在 Symfony4 中使用 FOUserbundle 向另一个用户显示用户配置文件? - How can I display a users profile to another user with in FOUserbundle in Symfony4? 如何使用Symfony2中的FOUserbundle向其他用户显示用户个人资料? - How can I display a users profile to another user with the FOUserbundle in Symfony2? WordPress-如何在用户个人资料之外更新用户元数据? 我已经提供了用于显示的代码 - WordPress - How can I update user meta data outside of the user's profile? I've provided the code I'm using to display
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM