简体   繁体   中英

Data not sticking to user profile

I'm trying to allow a user to upload files. A user needs to login, upload there files, then they are displayed. This does work, although when I log in as another user, those images of the first login user appear. When it should be each user can view only their uploads. PS the files uploaded do not appear on my DB, I have a blob column but it's empty even though I upload.

<?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>

Since the data is persisted ot has to be somewhere. Have you checked all rows in your table?

The problem that all images are shown is caused by your query select * from users means that you select everything from your database. To limit the response you have to add a where condition.

In your case you'd need a further column where you store the users ID and then yoi can use that as a filter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM