Help with button

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

Since you are using POST for the form action, the action must be to only the page itself. Once you include a “?” in the address, you turn it into an address with GET variables…which doesn’t quite work here.

So, instead, within the form tags, use a hidden element to pass along the data that doesn’t necessarily get supplied directly by the user.

<input type="hidden" name="uid" value="123456">

little confused with the code you provided, how would i direct that to execute the script in download.php? the value=“123456” what do i need to put there?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.