Hi
I suspect this is a really stupid question but I just can't figure this one out - its been awhile since I have done much PHP coding and I am REALLY rusty. I have two functions - one for just exporting data from MySQL to CSV and one that exports, then clears the database. Both are working great. However, I want to add an additional step that lets the user know the file was created successfully, and, if applicable, the database table has been cleared. Everything that I have tried to do has either resulted in no confirmation, or has given confirmation, but the CSV file was not created.
Below is my most recent attempt. In this one, the functions go through, but I get no confirmation. I really appreciate the help!
...else if ($_POST['action'] == 'export') {
//make connection
$dbconnection = dbconnect($host,$db,$user,$password);
$table = "passport_clues";
if ($dbconnection) {
$result = exportdata($dbconnection,$table);
if ($result) { $dataexported = 'true'; }
} else {
echo 'Sorry we were unable to connect to the database';
}
if ($dataexported == 'true') {
header('Location: clue_admin_process_success.php?action=export');
}
} else if ($_POST['action'] == 'delete') {
//make connection
$dbconnection = dbconnect($host,$db,$user,$password);
$table = "passport_clues";
if ($dbconnection) {
$result = exportdata($dbconnection,$table);
if ($result) { $dataexported = 'true'; }
} else {
echo 'Sorry we were unable to export the data';
exit;
}
if ($dataexported == 'true') {
$result = deletedata($dbconnection,$table);
if ($result) { $datadeleted='true'; }
} else {
echo 'Sorry we were unable to clear the data';
}
if ($datadeleted == 'true') {
header('Location: clue_admin_process_success.php?action=delete');
}
}
function exportdata($dbconnectionl,$table) {
$link = $dbconnection;
$result = mysql_query("SHOW COLUMNS FROM ".$table.";");
$i = 0;
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$csv_output .= $row['Field'].", ";
$i++;
}
}
$csv_output .= "\n";
$values = mysql_query("SELECT * FROM ".$table."");
while ($rowr = mysql_fetch_row($values)) {
for ($j=0;$j<$i;$j++) {
$csv_output .= $rowr[$j].", ";
}
$csv_output .= "\n";
}
$filename = $table."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
print $csv_output;
}
function deletedata($dbconnectionl,$table) {
$result = mysql_query("TRUNCATE TABLE ".$table."");
}