Im trying to use a button that will pull database info and allow download on a certain row, i have the following code on main.php with 2 buttons, the 2nd button works no problem redirecting to page to edit
<td>
<form action = "download.php?uid='.$clients_row2['uid'].'" method="POST">
<button type="submit"></i> Download</button>
</form>
</td>
<td>
<form action = "edituser.php?uid='.$clients_row2['uid'].'" method="POST">
<center><button type="submit" class="btn btn-primary"><i class="fa fa-cog"></i> Delete/Edit User</button></center>
</form>
</td>
The download button works, it redirects to download.php?uid=185 like it should but does not download the file, the code in the download.php is
<?php
include 'includes/database.php';
include 'includes/settings.php';
if(!isset($_SESSION))
{
session_start();
}
if(!isset($_SESSION['username']))
{
echo'
<script language="javascript">
window.location.href="index.php"
</script>
';
}
if(!isset($_GET['uid'])){
header('location: index.php');
}
$uid = filter_var($_GET['uid'], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH);
$doQuery = $mysqli->query("SELECT * FROM clients WHERE uid=".$uid." LIMIT 1");
while($x = $doQuery->fetch_array()) {
header("Content-length: ".strlen($x['AppData']));
header("Content-type: application/octet-stream");
header("Content-disposition: download; filename=Data-".$x['uid'].".bin");
echo $x['AppData'];
}
}
?>
Can anyone help, how do i make the button actually download the Data from table/column specified