Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Location
    Burlington, VT
    Posts
    125
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php saving into text file.

    hey everyone...
    i'm very new to php, it's my new project. Here's what I want to do:

    I think if I explain my project first it will help. I am making a resturaunt's site and I want to allow the owner to go into a page and fill in a form of what the menu will be for a specific day. Then the "menu" page will show users what has been input for different dates like today, tomorrow, this weekend.

    I can't use MySQL because they don't want to pay extra to add database support to the hosting plan... so I need to do this using text files... plus I don't think that there will be huge amounts of data, and speed isn't an issue.

    So is there a way make the form info save into a text file, and then be accessed by the public page to display the info? I really really hope I can do this without using a database.

    -Doug
    "The focused mind can pierce through stone."
    - Japanese Maxim

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your main problem is going to be ascertaining filenames, deducing current date, working out which file represents today/tomorrow etc. Not too tricky - just worth spending a while thinking about it before jumping into the coding.

    form to file...
    PHP Code:
    <?php
    if($_POST['course_title'] !== "") {
    $file_name "menu_files/tomorrows_menu.txt";
    $file_pointer fopen($file_name"a"); 
    $lock flock($file_pointerLOCK_EX); 
    if (
    $lock){
    $data '<h1>'.$_POST['course_title'].'</h1><br />'.$_POST['course_description'];
     
    fputs($file_pointer$data); 
     
    flock($file_pointerLOCK_UN); 

    fclose($file_pointer);
    }
    else {
    echo 
    '<form action="'.$PHP_SELF.'" method="post">';
    ?>
    title: <input type="text" name="course_title" /><br />
    desc: <textarea name="course_description"></textarea>
    </form>
    <?php
    }
    ?>
    Should get you heading in the right direction.
    Note: the folder 'menu_files' would need to be chmodded to allow write access for user and group. Fly typed so might need debugging.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Location
    Burlington, VT
    Posts
    125
    Thanks
    0
    Thanked 0 Times in 0 Posts

    thanks

    thank you, Ökii. This might have been too big of a project for my first one, but thanks to your help I may be able to get it working and learn a lot in the process.
    I'll see what I can do

    -Doug
    "The focused mind can pierce through stone."
    - Japanese Maxim


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •