Here’s my main form and download script. I need to pass some variables to download.php. These variables are derived from html select-list. How do I pass these variables to download.php?
Here’s my main form –
<td align="left"><select name="loc" id="loc" class="select-list">
<option value="\">Choose</option>
<option value="aa">AA</br>
<option value="bb">BB</br>
</select>
</td>
<strong>Click below to download:</strong> </br></br>
<span class="button" ><a href="download.php">Download (CSV)</a></span>
Here’s my download.php code –
header("Content-Disposition: attachment; filename=table.csv");
header("Content-type: text/csv");
$query = "SELECT * FROM table";
echo $out;
exit;
Now I want to pass the selected value from select-list to the download.php so that I can use predicates in my MYSQL SELECT query.
Any inputs please?? Thanks in advance.
Not exactly sure if this is what you mean, but hopefully it helps.
You need to use a HTML form with server-side PHP to handle the input.
Try looking at w3schools’ tutorial. Here’s a (very basic) example:
In the form:
In the download.php:
Also, make sure you sanitize your database queries, as well as initialize the db. w3schools link