I am trying to have my mysql database that is displayed on my webpage be exported to a csv on a button click, however it is not functioning as expected. I am attempting to do the following on the click of the export button, but when you click the Export CSV button it goes to a page "url/export.php" and gives an "error page does not exist webpage"
export button definition:
<div class="topnav">
<form method="post" action="export.php">
<input type="submit" name="export" value="CSV Export" class="btn btn-i"
<a class="active" href="#export">Export to CSV</a>
</form>
<div class="search-container">
<form action="/action_page.php">
<input type="text" placeholder="Search.." name="search">
<button type="submit"><i class="fa fa-search"></i></button>
</form>
</div>
</div>
export.php code:
<?php
//export.php
if(isset($_POST["export"])) {
$connect = mysqli_connect("localhost", "root", "password", "dbName");
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
$output = fopen("php://output", "w");
fputcsv($output, array('Username', 'Password', 'PhysicianID'));
$query = "SELECT * FROM Users";
$result = mysql_query($connect, $query);
while($row = mysqli_fetch_assoc($result)) {
fputcsv($output, $row);
}
fclose($output);
}
?>