How to get info from mysql to txt via php
I have a mysql database and a website in php. I want to create a button (or link) in php. When you press this button, it shall be downloading the information from a column in the database which should be saved in a txt file. (That come up in the browser the same way as when you choose to save anything).
Maybe this was poorly explained, but hope someone understand it.
Re: How to get info from mysql to txt via php
PHP Code:
<?php
$content = $_POST['content'];
$file = "file.txt";
$Saved_File = fopen($file, 'w');
fwrite($Saved_File, $content);
fclose($Saved_File);
?>
Just get your data to txt file from the database and not from the textarea.
Re: How to get info from mysql to txt via php
I didn't went so far until now but according to you, shouldn't this work?
PHP Code:
<?php
if(isset($ _POST['save']))
(
$ Content = $ row['table'];
$ File = "file.txt";
$ Saved_File = fopen($ file, 'w');
fwrite($ Saved_File, $ content);
fclose($ Saved_File);
)
?>
<Form action = "<? echo $ PHP_SELF; ?>"method =" post ">
<Input name="save" type="submit" value="Save">
</ Form>
Re: How to get info from mysql to txt via php
Be consistent with small / capital letters, see Save / save. If you add the line: echo "content=$content"; under $content = $row['table'];, what do you get up then?
Moreover, what I wonder is why you write to a file. Its not the user who should have the file? It's probably no point to save on the server.
Read the data from the database, set the HTTP-head clean and output data:
Content-Length: 185
Content-Type: text / plain
Content-Disposition: attachment; filename = content.txt
Re: How to get info from mysql to txt via php
Save/save? Why, it has something to say in this context? Save is not only the name of the button?
If you add the line: echo "content=$content"; under $content = $row['table'];, what do you get up then?
When it comes up content =.
Does well that it is empty, but in that case it does not save the page?
Re: How to get info from mysql to txt via php
There are many reasons to always be consistent with case, and not just where you think it is case insensitive. Do you have full control of what in html, css, php, javascript and sql is case sensitive and what is case insensitive? I see no advantage of such inconsistency. Based on such a mindset that it has nothing to say here, however, I can imagine that you also ignore the warnings and are only interested in getting out errors.