Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Saving data onto a txt file and reading it with PHP

  1. #1
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default Saving data onto a txt file and reading it with PHP

    Hi,

    I have been asked to make a booking sheet for rooms in my school.
    How do you say create a file with the date (with PHP) (20/09/06 or something) like booking_20.09.06.txt

    And the txt file will be like:

    Code:
    [c1]
    pd1=0
    pd2=1
    
    [c4]
    pd1=0
    pd2=1
    And then if you plan to book the room (C1) you will submit a form saying:

    Code:
    Room: C1
    Time: PD1
    Name: John Smith
    and if the text file says: "pd1=1" it will say "Sorry, booked." and if it says "pd1=0" it will change to 1 and say "Successfully booked."

    and every day to will check to see if the text file has been created and if not create a new one.

    And then if you want you can click "Times Booked" and it will show you the list of bookings like

    Code:
    PD1 = Booked
    PD2 = Not Booked
    Hope you don't get confused

    Anyone know the solution?

    Thanks,

    Peter
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  2. #2
    Join Date
    Sep 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    <?php
    $a=date("d").".". date("m").".".date("y");
    $a="booking_".$a.".txt";

    if (!file_exist($a)){
    $ac=fopen($a,"w") or die("There is Problem");

    //Put what do you want

    fclose($ac);
    }else
    {

    //Put what do you want

    }
    ?>

    Last edited by gameoverclocker; 09-22-2006 at 09:36 AM.

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by tech_support
    I have been asked to make a booking sheet for rooms in my school.
    This isn't homework, is it?

    How do you say create a file with the date (with PHP) (20/09/06 or something) like booking_20.09.06.txt
    When using dates in file names, use yyyy-mm-dd. This is a naturally sorting format, which makes managing the files easier.

    And the txt file will be like:

    Code:
    [c1]
    pd1=0
    pd2=1
    
    [c4]
    pd1=0
    pd2=1
    Must you use a text file? Must it use that format? Can you use a database, XML, or any other format?

    And then if you plan to book the room (C1) you will submit a form saying:

    Code:
    Room: C1
    Time: PD1
    Name: John Smith
    Wouldn't you want to get the name of the booker back? If so, where did you plan on storing that?

    Mike

  4. #4
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    This isn't homework, is it?
    No it isin't - It's just credit for me from the school - And I DON'T get paid

    When using dates in file names, use yyyy-mm-dd. This is a naturally sorting format, which makes managing the files easier.
    OK.

    Must you use a text file? Must it use that format? Can you use a database, XML, or any other format?
    I'm open to any other format except MySQL cause I can't get my MySQL working properly

    Wouldn't you want to get the name of the booker back? If so, where did you plan on storing that?
    Yes I would, and it will be on the same text file.


    Security is not a pirority. The only thing they'll be stealing is when the teacher has booked the room.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    date("d.m.y") works too, instead of three date statements and "." strings.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Yeah, it does so

    (Wow... a response in 8 minutes.)
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  7. #7
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    While I was working with this thing it came to this error message:

    Warning: fopen(............) [function.fopen]: failed to open stream: No such file or directory in ............. on line 13
    Can I change it to something like this:

    Code:
    Cannot find file.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Code:
    if (!(@file_exist($a))){
    $ac=@fopen($a,"w") or die("custom error here");
    
    //Put what do you want
    
    @fclose($ac);
    Using @function() makes it not return an error.
    Or you could just turn off error reporting all together.

    However, using @function() or die('error') is good, so you do know if/where it failed.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by tech_support
    Quote Originally Posted by mwinter
    Must you use a text file?
    I'm open to any other format except MySQL cause I can't get my MySQL working properly
    Using a database (any, it doesn't have to be MySQL) would be ideal. It would make concurrency (assuming that's a potential issue) and querying much simpler. If you're using PHP 5, SQLite may be an option, though finding out why MySQL isn't working would be a sensible thing to do, anyway.


    Quote Originally Posted by djr33
    date("d.m.y") works too, instead of three date statements and "." strings.
    Yes, though the format's still wrong.

    Code:
    'bookings-' . date('Y.m.d')
    Mike

  10. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Oh, I wasn't worried about order. I'm just saying you can do it all in one (and was copying the order above, for continuity).
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •