Page 1 of 1

new to php - write new info to file

Posted: Sat May 04, 2002 6:23 pm
by dssquirt
Hi.

I'm taking a web server class and for our last project we need to write a php program that takes information off of a form and adds it to a text file. We are inputting user ids and passwords adding them to the file and then letting users change the passwords if they so desire.

I am new to PHP and don't have time to read a book before this project is due. I know how to open a file and read from it, but how do I write information to it and save the file?

And if I want to check for information and then change it, is there an easy way to do it?

Thanks very much. I really want to learn PHP, and I guess I am getting a crash course. This project was just assigned and is due in 8 days. I had no background in PHP before this and I'm picking it up as fast as I can.

Dssquirt

Posted: Sat May 04, 2002 6:33 pm
by fatal
Well you need to check out some file handling functions. Well to write/save to a file its:

$fp = fopen( $file, 'w'); // a is to open the file to ammend info to it
fputs($fp, "hello... from a file!");

$read = fgets($file, 255);

echo"<b>Contents</b>: " . $read;

fclose($fp);

Posted: Sat May 04, 2002 7:21 pm
by hob_goblin

Posted: Sat May 04, 2002 10:34 pm
by phice
I wish I had such a class that made me do an assignment like that! :P

Posted: Sun May 05, 2002 3:26 am
by HiDDeN
I wish I had such a class that made me do an assignment like that!
Well classes are not completely implemented in PHP it's just slowing down your code, furthermore your project is not such a complex thing to write tons of classes code.

Posted: Sun May 05, 2002 4:05 am
by mikeq
Hi,

They are not talking about class in OO terms, they are talking about class as in learning, courses, training etc

Posted: Sun May 05, 2002 11:22 am
by sam
HiDDeN wrote:
I wish I had such a class that made me do an assignment like that!
Well classes are not completely implemented in PHP it's just slowing down your code, furthermore your project is not such a complex thing to write tons of classes code.
Ha Ha... That is classic :mrgreen:

Cheers Sam