Do Things Blog, Hospitality Management – Study in Switzerland
How to shop internet shape data in a text file
You can save your web form information in a textual content record. In preference to saving it in a MySQL desk the usage of a simple PHP script. The benefit of doing this is that you may not have the MySQL server. Hooked up to your server or you may want to keep your internet form statistics in some other shape.
In fact if you store your net shape records in a text document as comma separated values (CSV). You may later on import your statistics in any record layout. For example, after downloading your text document. You could import the values in an Excel sheet. Or into an Access table, or in a while, even in a MySQL desk. You can use it with any software the makes use of comma separated values.
Saving net shape facts in a text file with PHP
Why PHP? First of all, I’m greater secure with PHP. Second, that allows you to obtain this you need a few server facet scripting. And there may be a 99.99% hazard that your internet host lets in PHP scripts. So that’s now out of our way.
Do Things Blog, Suppose you have got the following internet form in your internet site or weblog:
Since we handiest want an example so we’ll have just fields for the shape, particularly name and e mail. Next, create a text document containing this line:
Do Things Blog, Name,Email
And call it as, say, formdata.Txt. As you may see, it has a comma among the two headers. Also press the Enter key. Once after writing Email in order that that the cease of record pointer is in the next line.
Upload this file to the folder where you’ve got your web shape report. And the PHP script report so that it will save your shape information in this newsletter record.
Make sure your text document is writable at the server (the report permission must be set to 666). And you could do it by means of proper-clicking it via your FTP patron.
Now to the document where the actual action takes place, this is, “manner-form-statistics.Php”. This record contains the subsequent traces of code:
The first two lines saves the net form publish information in local PHP variables. The 3rd line opens the text with the best permission. In PHP we can open documents with difference permissions, however right here.
“A” approach open the document in write-mode and append the new data (without overwriting the present information. You can check with PHP legit documentation for all record starting permissions. Just remember that a wrong permission can delete your file or erase all your records.
The 4th line creates a string that mixes the two values call and electronic mail puts a comma between them. And then inserts the brand new line character. So that the give up of document pointer actions to the following line.
Do Things Blog, The fwrite feature writes the newly created line and the last code is very smooth to understand.
If you are not saving very critical records, saving your net form information in a textual content document is higher. Than saving it in a database desk as then it’s far simpler to access it with out greater programming information.