diff --git a/public/export_db.php b/public/export_db.php new file mode 100644 index 0000000..06de640 --- /dev/null +++ b/public/export_db.php @@ -0,0 +1,97 @@ +connect_error) { + die("Connection failed: " . $conn->connect_error); +} + +// ---- Retrieve all table names from the database ---- +$tables = []; +$res = $conn->query("SHOW TABLES"); +if ($res) { + while ($row = $res->fetch_array(MYSQLI_NUM)) { + $tables[] = $row[0]; + } + $res->free(); +} + +// ---- Handle export ---- +if (isset($_POST['export']) && isset($_POST['table_name'])) { + $raw = $_POST['table_name']; + $table = trim($raw, " \t\n\r\0\x0B`'\""); + + // Validate table name exists in the database + if (!in_array($table, $tables, true)) { + die("Invalid table selection: " . htmlspecialchars($table)); + } + + // Retrieve all rows from selected table + $sql = "SELECT * FROM `" . $conn->real_escape_string($table) . "`"; + $result = $conn->query($sql); + if (!$result) { + die("Error retrieving data: " . $conn->error); + } + + // ---- Prepare CSV download ---- + header('Content-Type: text/csv; charset=utf-8'); + header("Content-Disposition: attachment; filename={$table}_export.csv"); + + $out = fopen('php://output', 'w'); + if ($result->num_rows > 0) { + $first = $result->fetch_assoc(); + fputcsv($out, array_keys($first)); // column headers + fputcsv($out, $first); // first row + while ($row = $result->fetch_assoc()) { + fputcsv($out, $row); + } + } else { + fputcsv($out, ["No records found in '{$table}'"]); + } + + fclose($out); + $result->free(); + $conn->close(); + exit; +} +?> + + +
+ +Database:
+ + + + +No tables found in the database .
+ + +Choose a table and click “Export to CSV” to download its contents.
+ + \ No newline at end of file diff --git a/public/refile/include/nav.php b/public/refile/include/nav.php index 8396d09..18d2a7b 100755 --- a/public/refile/include/nav.php +++ b/public/refile/include/nav.php @@ -23,7 +23,7 @@ Summary Mismatched Trays Hold Shelf List - Alma Stats'; + Alma Stats'; } ;?> Item Check