Link to home
Start Free TrialLog in
Avatar of ARAVINDBABU
ARAVINDBABU

asked on

writing the HTML form posted fields into a text file with tab spaces

Hi,

I have 2 questions and i think i have gave enough points. both are related to file handling in php.

first:

I have some HTML forms with different fields
example:

form1                             form2                          form3                       and so on upto 6 forms

firstname                      username                       firstname
username                      sex                                your city
lastname                       email                             your country
age

i have a text file like userdetails.txt. The file contains all the fields seperated by tab spaces.

example:

username  firstname  lastname  sex email  age  city  country and so on.

so when the user submits the form i need to enter all the fields of forms into the text file.It is not mandatory that user should enter all the fields. If he leaves some fields empty then in the text file the values corresponding column will be null.

second:

There is a text file will some numbers in it.
example
file.txt
2
3
4
5
and so on.
i want to read the last number from the file . i take some number as user input from a form and i want to add that many numbers starting from the last number taken from file.
example:
user input: 4
read last entry from file:5
append to file 6  7  8  9. these numbers must be appended in each line into the text file

I also have an idea of implementing the above but has some problems. If the first case does not work then i am thinking of database table,which is easy to implement. Second case i am able to get the numbers to put into file. But i dont get an idea to keep the numbers in seperate lines.

Thanks
babu.
Thanks


Avatar of Zyloch
Zyloch
Flag of United States of America image

For the first case, although possible to code, I recommend using a database table definitely.

For the second, you can do something like this:

<?php

$user_input = 4; //get user input from user though

$sep = "\n"; //\r\n if on Windows system

$file = "number_file.txt";
$numbers = array();
$numbers = file($file);

$last_number = $numbers[count($numbers) - 1];

$output = "";
for ($i = 1;$i <= $user_input;$i++)
{
   $output .= ($last_number + $i) . $sep;
}

$fp = fopen($file, "a");
fwrite($fp, $output);
fclose($fp);

?>
Avatar of ARAVINDBABU
ARAVINDBABU

ASKER


thanks for reply
i have already implmented the second case using the same file method.

how about the first case.any idea.
ASKER CERTIFIED SOLUTION
Avatar of Zyloch
Zyloch
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.
I will leave the following recommendation for this question in the Cleanup topic area:
    Accept: Zyloch

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

- Neester -
EE Cleanup Volunteer