Results 1 to 6 of 6

Thread: How to get info from mysql to txt via php

  1. #1
    Join Date
    Apr 2010
    Posts
    28

    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.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    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.

  3. #3
    Join Date
    Apr 2010
    Posts
    28

    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>

  4. #4
    Join Date
    Nov 2008
    Posts
    1,022

    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

  5. #5
    Join Date
    Apr 2010
    Posts
    28

    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?

  6. #6
    Join Date
    Nov 2008
    Posts
    1,022

    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.

Similar Threads

  1. Replies: 4
    Last Post: 13-01-2011, 01:08 AM
  2. need info about your Backlog?
    By Gaia in forum Video Games
    Replies: 5
    Last Post: 23-11-2010, 06:17 AM
  3. Want info regarding the subnet
    By Naimah in forum Networking & Security
    Replies: 5
    Last Post: 06-10-2010, 01:48 PM
  4. mysql config file in MySQL
    By Netorious in forum Software Development
    Replies: 4
    Last Post: 18-03-2010, 09:43 PM
  5. Replies: 3
    Last Post: 07-11-2009, 09:36 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,726,998,339.68087 seconds with 17 queries