簡體   English   中英

數據不符合用戶配置文件

[英]Data not sticking to user profile

我正在嘗試允許用戶上傳文件。 用戶需要登錄,上傳文件,然后顯示它們。 這確實有效,但是當我以另一個用戶身份登錄時,會出現第一個登錄用戶的圖像。 應該是每個用戶只能查看他們的上傳。 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可以將其用作過濾器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM