Question:
HTML/PHP Form Processing Codes to save inputs to text file?
SilverShadow
2009-05-27 21:58:53 UTC
How can i create an html form and a php file that capture first and last name and e-mail of website visitors and save it to a text file in the same server directory
then redirect the visitor to an html "thank you" page.

but i need to achieve this with few conditions:

1. when i reload the html form again i want it to show blank/empty fields again and not save previous input (because i tried a code before and it save the old input)

2. i need to put the php file in a remote server not local one and it just process the input/output and send output text file back to the other server.

3. i need it to not erase the old saved value in the text files,
maybe using \n for a new line in the fwrite function? but i don't know how to use it, besides not erasing the old value like i said.

Thank you very much



Thank you
Three answers:
anonymous
2009-05-27 22:25:33 UTC
I'd advise using MySQL database to store your data. If you really need it in a text file then your looking at having to, when your in the process of writing the data to the file, you have to store all previous data in a variable or array or something then write the new information then rewrite the old information so it's going in chronological order. I did that before I knew how to use MySQL.



There's no HTML form that will store the data there has to be javascript or PHP behind it, chances are it was your computers/browsers cookies that was storing your information.
Tay K
2009-05-28 06:51:13 UTC
First of all, it sounds like you should use a database server instead of a text file. There are a few reasons:



- Files can be difficult to parse compared to a simple database query.

- Servers often do not allow PHP scripts to read/write files because of security concerns.

- Database servers can be queried remotely, which totally skips the step of transferring a file from one server to another.



As for your actual question...



1. This shouldn't be a problem in the first place.

2. There's no practical way to do this besides using a database server. You'd have to manually transfer the file.

3. Use fopen("filename", "a") to append to the end of the file.



Unless you really, really need to just use a plain text file then go for a relational database (e.g. MySQL, PostgreSQL). If you need to create a text file from the data then you can just write another script to create a text file in the format that you want.
parse error
2009-05-28 08:16:24 UTC
save the inputted values into mysql table:

http://phpcode.hu/teszt/table_code/



or save the inputted values into flat file database, called SQL lite:

http://phpcode.hu/teszt/sqlite_tables/


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...