php - 数据不粘在用户个人资料上

标签 php mysql upload

我正在尝试允许用户上传文件。用户需要登录,上传文件,然后显示它们。这确实有效,尽管当我以另一个用户身份登录时,会出现第一个登录用户的那些图像。当应该是每个用户只能查看他们上传的内容时。 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>

最佳答案

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

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

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

关于php - 数据不粘在用户个人资料上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56179313/

相关文章:

mysql join里面插入

mysql - 静默安装 MySql 作为服务

grails - 将大文件(> 1GB)上传到grails3

actionscript-3 - Flash AS3 FileReference-一次选择并上传多个文件

php - 我可以获得可版本化 Doctrine 记录的版本集合吗?

php - 在不允许时添加到数组的正确异常类型?

php - EasyAppointments 和 Bootstrap 网站之间的共享登录 session

php - 如何使用 Foreach 在 PHP 中显示 MYSQL 全文查询的输出

php - 页面不会用 PDO 语句回显结果

database - 在 Amazon VM 上上传 Postgres 数据库