This is only an example and threat it as example. Take care about security too. So don't copy and paste :) You could do like this: weetat wrote: > Hi all, > > I have code below which save MYSQL to csv file. I am using ADODB > library to do this. > > The saving MYSQL to csv file is ok . > However i need to allow the the user to enter file name for csv file. > > Anybody have any ideas how to do this? Thanks > <? > > $sql = $_SESSION['CSV_SQL']; > $_logger = new Log4jLogger(); > $_logger->logdebug('sql:', $sql); > if( !isset( $filename ) ) $filename = $_GET["filename"]; if( empty( $filename ) ) { ?> <script language="JavaScript"> <!-- var filen = prompt( "Please provide a filename.", "" ); if( filen.length ) { document.location = '<?=$PHP_SELF?>?filename=' + filen; } //--> </script> <? } else { > if (!isset($_REQUEST['maintainall'])) { //$filename = 'tbl_chassis.csv'; > CSVUtil::UploadTbtoCSV($sql, $filename); > unset($_SESSION['CSV_SQL']); > header('Location: ../maintain.php?csv'); > exit; > } else { > //$sql = 'SELECT * from tbl_card'; //$filename = 'tbl_card.csv'; > CSVUtil::UploadTbtoCSV($sql, $filename); > unset($_SESSION['CSV_SQL']); > header('Location: ../maintainall.php?csv'); > exit; > } } > > function UploadTbtoCSV($sqltext,$filename) > { > $_logger = new Log4jLogger(); > $_logger->logdebug("starting.. upload tb to csv"); > > $rs = dbQuery($sqltext); > $rs->MoveFirst(); > $_logger->logdebug("UploadTbtoCSV csvpath:",CSV_PATH); > > $fp = fopen(CSV_PATH."/".$filename, "w"); > > if ($fp) { > rs2csvfile($rs, $fp); > fclose($fp); > $_logger->logdebug("starting upload tb to csv done"); > } > > > > } > ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php