The resumes table contains 3 data and 3 files that are submitted to different employers. When I log in to Employer (2 (in resumes table fk_user_id = 2)) I get 3 download buttons of the other 2 employers as well.
What might be the reason?
I just require download button according to the resumes table and that too submitted to the specific employer. When I log in as Employer (2) I got 3 different download buttons.
resume_manage.php
<?php
include 'includes/header.php';
include 'filesLogic.php';
include 'includes/sidebar.php';
?>
<div class="content-wrapper">
<!-- START PAGE CONTENT-->
<div class="page-heading">
<h1 class="page-title">Applied Jobs List</h1>
<ol class="breadcrumb">
<li><a href="../../../index.php"><i class="fa fa-dashboard"></i> Home</a></li>
<li class="active">Applied Jobs List</li>
</ol>
</div>
<div class="page-content fade-in-up">
<div class="ibox">
<div class="ibox-head">
<div class="ibox-title">Data Table</div>
</div>
<div class="table-responsive ibox-body">
<table class="table table-striped table-bordered table-hover" id="example-table" cellspacing="0" width="100%">
<thead>
<tr>
<th>User Id</th>
<th>Resume</th>
<th>Employer Id</th>
<th>User Email</th>
<th>Reply</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tfoot>
<tr>
<th>User Id</th>
<th>Resume</th>
<th>Employer Id</th>
<th>User Email</th>
<th>Reply</th>
<th>Status</th>
<th>Actions</th>
</tr>
</tfoot>
<tbody>
<?php
$detail="SELECT * FROM resumes where fk_user_id = '$user_id'";
$detailqry = mysqli_query($conn, $detail);
while($row = mysqli_fetch_array($detailqry)){
$id = $row['resume_id'];
?>
<tr>
<td><?php echo $row['user_id'];?></td>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['job_id'];?></td>
<td><?php echo $row['user_email'];?></td>
<td>
<?php
foreach ($files as $file){?>
<a href="resume_manage.php?file_id=<?php echo $file['resume_id'] ?>">Download</a>
<?php } ?>
</td>
<td>
<a class="btn btn-danger" href="write_resume_reply.php?sid=<?php echo $row['resume_id']; ?>"><b>Write Reply</b>
</a>
</td>
<?php
if($row['active']==1){
echo '<td>';
echo "<font color='#8ed100'><b>Already Sent</b></font>";
$buttonText = "SENT";
}else{
echo '<td>';
echo "<font color='#750000'><b>Not Sent</b></font>";
$buttonText = "SEND";
}
echo "</td>";
?>
<td class="text-center">
<a class="btn btn-danger" href="action_resume.php?sid=<?php echo $row['resume_id']; ?>"><b><?php echo $buttonText; ?></b>
</a>
</td>
</tr>
<?php }?>
</tbody>
</table>
</div>
</div>
</div>
<!-- END PAGE CONTENT-->
<footer class="page-footer">
<div class="font-13">2021 © <b>Job4Students</b> - All rights reserved.</div>
<div class="to-top"><i class="fa fa-angle-double-up"></i></div>
</footer>
</div>
</div>
<!-- BEGIN PAGA BACKDROPS-->
<div class="sidenav-backdrop backdrop"></div>
<div class="preloader-backdrop">
<div class="page-preloader">Loading</div>
</div>
<!-- END PAGA BACKDROPS-->
<!-- CORE PLUGINS-->
<script src="./assets/vendors/jquery/dist/jquery.min.js" type="text/javascript"></script>
<script src="./assets/vendors/popper.js/dist/umd/popper.min.js" type="text/javascript"></script>
<script src="./assets/vendors/bootstrap/dist/js/bootstrap.min.js" type="text/javascript"></script>
<script src="./assets/vendors/metisMenu/dist/metisMenu.min.js" type="text/javascript"></script>
<script src="./assets/vendors/jquery-slimscroll/jquery.slimscroll.min.js" type="text/javascript"></script>
<!-- PAGE LEVEL PLUGINS-->
<script src="./assets/vendors/DataTables/datatables.min.js" type="text/javascript"></script>
<!-- CORE SCRIPTS-->
<script src="assets/js/app.min.js" type="text/javascript"></script>
<!-- PAGE LEVEL SCRIPTS-->
<script type="text/javascript">
$(function() {
$('#example-table').DataTable({
pageLength: 10,
//"ajax": './assets/demo/data/table_data.json',
/*"columns": [
{ "data": "name" },
{ "data": "office" },
{ "data": "extn" },
{ "data": "start_date" },
{ "data": "salary" }
]*/
});
})
</script>
</body>
</html>
filesLogic.php
<?php
// connect to the database
include '../includes/connection.php';
$conn = mysqli_connect("localhost","root");
// Select Database
if (!$conn) {
error_log("Failed to connect to MySQL: " . mysqli_error($connection));
die('Internal server error');
}
// 2. Select a database to use
$sql = mysqli_select_db($conn, 'Students_Jobsite');
if (!$sql) {
error_log("Database selection failed: " . mysqli_error($connection));
die('Internal server error');
}
$detail = mysqli_select_db($conn, 'Students_Jobsite');
$sql = "SELECT * FROM resumes";
$result = mysqli_query($conn, $sql);
$files = mysqli_fetch_all($result, MYSQLI_ASSOC);
// Downloads files
if (isset($_GET['file_id'])) {
$id = $_GET['file_id'];
// fetch file to download from database
$sql = "SELECT * FROM resumes WHERE resume_id=$id";
$result = mysqli_query($conn, $sql);
$file = mysqli_fetch_assoc($result);
$filepath = '../uploads/' . $file['name'];
if (file_exists($filepath)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($filepath));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize('uploads/' . $file['name']));
readfile('uploads/' . $file['name']);
// Now update downloads count
$newCount = $file['downloads'] + 1;
$updateQuery = "UPDATE files SET downloads=$newCount WHERE resume_id=$id";
mysqli_query($conn, $updateQuery);
exit;
}
}