sarab99 Posted June 14, 2008 Share Posted June 14, 2008 Hi, I need help on how to export the output result of my php code below to text file. <?php echo "<CENTER><form method='POST' enctype='multipart/form-data' action='$row[salt]'> user_name <br> <input type=\"text\" name=\"login\" value=\"\"> <br>password<br> <input type=\"text\" name=\"passwd\" value=\"\"> <br>dataBase_Name <br> <input type=\"text\" name=\"port\" value=\"\"> <br> <input type=\"submit\" value=\"Show\"> <div align=\"center\"><br></form>"; $user = $_POST['login']; $pass = $_POST['passwd']; $dbname = $_POST['port']; $LINK = mysql_connect ("localhost",$user,$pass) or die("Couldn't connect to mysql<br>". mysql_error()); $con = mysql_select_db($dbname) or die("Couldn't select database: $dbname<br>" . mysql_error()); $q = "select * from user"; $result = mysql_query ($q) or die("Problem with the query: $q<br>" . mysql_error()); $res = mysql_query("select * from user"); $num = mysql_num_rows($res); echo '<CENTER> ' . $num . ' '; ?> <textarea method='POST' rows=20 cols=100 wrap=off> <?php $i = 1; while ($row = mysql_fetch_assoc ($result)) { echo sprintf("%5d",$i) . '|' . $row['username'] . '|'. $row['email'] . '|'. $row['password'] . '|'. $row['salt'] ."\n"; $i++; } ?> what I need is a link when I press it the file start downloading the data as txt. with same column in the script code. any help will be highly appreciateed. Link to comment https://forums.phpfreaks.com/topic/110240-export-mysql-to-text-file-via-php/ Share on other sites More sharing options...
marklarah Posted June 15, 2008 Share Posted June 15, 2008 So have link with a get variable (or post), and store the record ID of the result in it. In this page, lookup via the db the content, the fwrite to a txt: http://uk3.php.net/fwrite Then display link to it. Link to comment https://forums.phpfreaks.com/topic/110240-export-mysql-to-text-file-via-php/#findComment-565724 Share on other sites More sharing options...
sarab99 Posted June 15, 2008 Author Share Posted June 15, 2008 as I am a newbie this action seems a complecated proccess for me. I appreciated if any one can update my script as needed. many thanks Link to comment https://forums.phpfreaks.com/topic/110240-export-mysql-to-text-file-via-php/#findComment-565870 Share on other sites More sharing options...
marklarah Posted June 15, 2008 Share Posted June 15, 2008 what exactly is the data you want exporting? Link to comment https://forums.phpfreaks.com/topic/110240-export-mysql-to-text-file-via-php/#findComment-566065 Share on other sites More sharing options...
corbin Posted June 15, 2008 Share Posted June 15, 2008 So have link with a get variable (or post), and store the record ID of the result in it. In this page, lookup via the db the content, the fwrite to a txt: http://uk3.php.net/fwrite Then display link to it. Or, instead of making a temporary file, you could just fetch the data and send the client headers so that it makes them download it. (Google "php force download") Pseudo code example: if($_POST) { //echo out data and send headers to suggest to the client's webbrowser that it try to download the file } else { //display a form so the user can say what data he/she wants. } Link to comment https://forums.phpfreaks.com/topic/110240-export-mysql-to-text-file-via-php/#findComment-566087 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.