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

<form action = "download.php?uid='.$clients_row2['uid'].'"   method="POST">
<button type="submit"></i> Download</button>
<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>

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

include 'includes/database.php';
include 'includes/settings.php';


	<script language="javascript">

		header('location: index.php');
	$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.