-
Notifications
You must be signed in to change notification settings - Fork 1
/
export.php
35 lines (34 loc) · 939 Bytes
/
export.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
session_start();
error_reporting(E_ERROR | E_PARSE);
include_once 'connection.php';
if(isset($_SESSION['sid']) ){
if($_SESSION['sid']!=session_id())
header('Location: index.php');
}
if(isset($_POST['export'])){
if(isset($_POST['salary'])){
$salary = $_POST['salary'];
}
}
$sql = "select * from employee where salary<=".$salary."";
$result = $conn->query($sql);
if (!$result) die('Couldn\'t fetch records');
$num_fields = mysql_num_fields($result);
$headers = array();
for ($i = 0; $i < $num_fields; $i++) {
$headers[] = mysql_field_name($result , $i);
}
$fp = fopen('php://output', 'w');
if ($fp && $result) {
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="export.csv"');
header('Pragma: no-cache');
header('Expires: 0');
fputcsv($fp, $headers);
while ($row = $result->fetch_array(MYSQLI_NUM)) {
fputcsv($fp, array_values($row));
}
die;
}
?>