473,472 Members | 2,211 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Read and write flat files using php

3 New Member
hello

i want to store submitted data of forms to a text file and retrieve from there, coz my hosting server package does not have the features of mysql database. can any one help me in this issue..

best regards
Jul 11 '07 #1
4 5808
ak1dnar
1,584 Recognized Expert Top Contributor
hello

i want to store submitted data of forms to a text file and retrieve from there, coz my hosting server package does not have the features of mysql database. can any one help me in this issue..

best regards
Hi there,
This a simple script to write such data to text file.Commonly saying flat files.

Write user inputs :

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if (isset($_POST['submit'])) {
  3. $Fname = $_POST['fname'];
  4. $Lname = $_POST['lname'];
  5. $fp = fopen("data.txt","a");// Open data.txt for writing
  6. if(!$fp) {
  7.     echo 'Error, the file could not be opened or there was an error creating it.';
  8.     exit;
  9. }
  10. if(@fwrite($fp, $Fname.'|'.$Lname."\n")){
  11. echo 'Record Added';
  12. }else{
  13. echo 'Failed';
  14. }
  15. fclose($fp);
  16. }
  17. ?>
  18. <html>
  19. <body>
  20. <form name="input" method="post" action="<?php echo $_SERVER['SCRIPT_NAME']?>">
  21. <p><label for="firstname">First Name: </label>
  22. <input type="text" name="fname" id="fname" /></p>
  23. <p><label for="firstname">Last Name: </label>
  24. <input type="text" name="lname" id="lname" />
  25. <p><input type="reset" name="reset" value="reset" /> 
  26. <input type="submit" name="submit" value="submit" /></p>
  27. </form>
  28. </body>
  29. </html>
  30.  
  31.  
Read flat file back.

read this thread

But I will never recomend this type of flat file system for record handling. its better only for few records only. when the file gets lagrer it won't be able to mange anymore.

Thanks!
-Ajaxrand
Jul 11 '07 #2
ak1dnar
1,584 Recognized Expert Top Contributor
Thread title changed to better describe the scenario

Earlier: want to store submitted info to text file
Recent: Read and write flat files using php
Jul 11 '07 #3
riyadh81
3 New Member
thank you very much for your perfect guidance.

the script you provided was perfect n worked. if i want to show the insert data in of text file to php page. how can i do that thing

thanking you
Jul 11 '07 #4
ak1dnar
1,584 Recognized Expert Top Contributor
thank you very much for your perfect guidance.

the script you provided was perfect n worked. if i want to show the insert data in of text file to php page. how can i do that thing

thanking you
Do you want to read the inserted records from flat file again.
Read the Thread Link I gave in my previous post.
Jul 11 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Yang Li Ke | last post by:
Hi guys! I have some datas that I must check everytime a visitor comes to my site What is better to do: 1- Read data from a file or 2- Read data from a mysql db Thank you
1
by: Steve Jenkins | last post by:
Hi, Wonder if someone could help me. I'm looking for a PHP/MySQL based search engine that can search flat files i.e. build it's own index from flat files. I've used Apaches' Lucene before...
2
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers...
19
by: Holger Hasselbach | last post by:
- The value of the object allocated by the malloc function is used (7.20.3.3). - The value of any bytes in a new object allocated by the realloc function beyond the size of the old object are used...
12
by: J. G. | last post by:
I'm looking at rewriting some stand-alone Pro*COBOL applications that read flat files and spit out some reports. Is there any way to mimic COBOL's ability to read lines from a flat file into a...
2
by: Thomas | last post by:
Hi, Do you know of the source for classes reading and writing flat files, including providing meta data such as column format, datatype, alignment, defaults and constraints. I need it for...
8
by: dosworldguy | last post by:
I have been having a very peculiar issue from a long time. I have an application where multiple clients read from a shared set of files. When a record is changed, sometimes the win9x clients...
6
by: Peter | last post by:
Greetings, I'm having trouble deciding on whether to go with a flat file or DB driven architecture for a wee personal website. I'd like to be able to update HTML files online and this is my only...
9
by: =?Utf-8?B?TmF2YW5lZXRoLksuTg==?= | last post by:
Hello I am developing a system for user tracking. In this I am tracking all the visitors that came to my website. i developed this using a HTTPModule and storing the data in a SQL Server...
3
by: stephen | last post by:
I had to use use ssis 2005 in a short project recently & had little time to work it out. I was importing a whole bunch of flat files into SQL Server tables with many derived columns and...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.