I have a database, in that database is a table with 2 columns:
Column 1: id
Column 2: filename
At the moment I have 3 entries in the table, each one has their own unique id (id is set to auto-increment with each entry). each separate entry has an id of:
1
2
3
I'm using a While loop in my page to display each item:
<?php
require_once("parse_files/connect.php");
$query1 = "SELECT * FROM uploads";
$result1 = mysqli_query($connection, $query1);
while($row1 = mysqli_fetch_assoc($result1)) {
$upload_id = $row1['id'];
$upload_filename = $row1['filename'];
?>
<?php echo $upload_filename?><br>
<button onClick="remove_file();">Remove</button>
<?php } ?>
Here I have echo'd out the filename, And next to it I have displayed a button that will allow the user to delete the file. For testing purposes I have created this small script to see what value my javascript pulls out when I click the button:
<script>
function remove_file(){
var filename = '<?php echo $upload_id?>'
alert(filename);
}
</script>
When I test it I place the script within the while loop, so that I can get the value of the id (Or so i hoped), but it just doesn't work. When I click the button next to the corresponding filename, I want it to show that products id, but instead it shows me the last entries (3) no matter which button I click. I might be taking the complete wrong direction with this, could someone please point me in the right direction?