View Full Version : Saving data onto a txt file and reading it with PHP
tech_support
09-22-2006, 07:41 AM
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:
[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:
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
PD1 = Booked
PD2 = Not Booked
Hope you don't get confused :p
Anyone know the solution?
Thanks,
Peter
gameoverclocker
09-22-2006, 08:42 AM
<?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
}
?>
;)
mwinter
09-22-2006, 12:42 PM
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:
[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:
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
tech_support
09-23-2006, 04:40 AM
This isn't homework, is it?
:D No it isin't - It's just credit for me from the school - And I DON'T get paid :p
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. :p
djr33
09-23-2006, 04:48 AM
date("d.m.y") works too, instead of three date statements and "." strings.
tech_support
09-23-2006, 04:49 AM
Yeah, it does so
(Wow... a response in 8 minutes.)
tech_support
09-24-2006, 06:38 AM
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:
Cannot find file.
djr33
09-24-2006, 06:51 AM
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.
mwinter
09-24-2006, 10:25 PM
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.
date("d.m.y") works too, instead of three date statements and "." strings.
Yes, though the format's still wrong. :p
'bookings-' . date('Y.m.d')
Mike
djr33
09-25-2006, 12:21 AM
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).
tech_support
09-25-2006, 07:15 AM
Well, each time I install MySQL it gives me an error '0'
Dunno what that means... :confused:
mwinter
09-26-2006, 01:11 AM
Well, each time I install MySQL it gives me an error '0'
Dunno what that means... :confused:
Can't say I've ever come across it. Do you have adminstrator (root) access when installing? In any case, installation issues are best directed to dedicated MySQL support forums, not DD.
You didn't mention what exact version of PHP you're running.
Mike
tech_support
09-26-2006, 10:01 AM
PHP Version 5.1.5
If you want what phpinfo() says then here: (inserted as an attachment)
and...
I'm using the DevSide.net Suite
which includes PHP, MySQL, Perl etc.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.