【问题标题】:Data not sticking to user profile数据不符合用户个人资料
【发布时间】:2019-05-17 03:48:00
【问题描述】:

我正在尝试允许用户上传文件。用户需要登录,上传文件,然后显示。这确实有效,尽管当我以另一个用户身份登录时,会出现第一个登录用户的图像。什么时候应该是每个用户只能查看他们的上传。 PS上传的文件没有出现在我的数据库中,我有一个blob列,但即使我上传它也是空的。

<?php
mysql_connect("xxx","root","xxx");
mysql_select_db("alter");
if(isset($_POST["submit1"]))
{
$image = addslashes(file_get_contents($_FILES['f1']['tmp_name']));
mysql_query("insert into users values('','$image')");
}


if(isset($_POST["submit2"]))
{
   $res=mysql_query("select * from users");
   echo "<table>";
   echo "<tr>";

   while($row=mysql_fetch_array($res))
   {
   echo "<td>"; 
   echo '<img src="data:image/jpeg;base64,'.base64_encode($row['image1'] ).'" height="200" width="200"/>';
   echo "<br>";
   ?><a href="delete.php?id=<?php echo $row["id"]; ?>">Delete</a> <?php
   echo "</td>";

   }
   echo "</tr>";

   echo "</table>";

}
?>
</body>


</div>

<script>
// Get the Sidebar
var mySidebar = document.getElementById("mySidebar");

// Get the DIV with overlay effect
var overlayBg = document.getElementById("myOverlay");

// Toggle between showing and hiding the sidebar, and add overlay effect
function w3_open() {
  if (mySidebar.style.display === 'block') {
    mySidebar.style.display = 'none';
    overlayBg.style.display = "none";
  } else {
    mySidebar.style.display = 'block';
    overlayBg.style.display = "block";
  }
}

// Close the sidebar with the close button
function w3_close() {
  mySidebar.style.display = "none";
  overlayBg.style.display = "none";
}
</script>

【问题讨论】:

    标签: php mysql upload


    【解决方案1】:

    由于数据是持久化的,因此必须在某个地方。您是否检查了表中的所有行?

    显示所有图像的问题是由您的查询引起的 select * from users 意味着您从数据库中选择了所有内容。要限制响应,您必须添加 where 条件。

    在您的情况下,您需要另一个列来存储用户 ID,然后 yoi 可以将其用作过滤器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-02
      • 2010-12-01
      • 2013-05-06
      相关资源
      最近更新 更多