Storing data from form into txt file and reading
Posted: Thu Jun 04, 2009 5:13 am
Ok... i have a task to create a script that will Store data from html form into .txt file(every in a new line so later it could read everything in a new line) and then in a next page it will read from that txt file and sort everything in a list <ul>
<li></li></ul>
i can give you code that I have creatred and it stores data from form into txt (names) and it stores them each one next to one before : mikejohnpeterpatrickclarasony
And it should look like :
mike
john
peter
patrick
clara
sony
And in a next page it should dysplay everything from that txt file in this form:
this is a code that i created :
html page aka form page : htmldio.html:
<body>
<form action="podaci.php" method="post">
Ime:
<input type="text" name="ime" align="left" />
<input type="submit" value="Dodaj ime
" />
</form>
</body>
php page for inserting data (ime) into txt : podaci.php:
<?php
$ime=$_POST['ime'];
$file="podaci.txt";
$open=fopen($file,"a") or die ("Nisam otvorio fajl sorry do mene je ;(");
fwrite($open,$ime."\r\n");
fclose($open);
echo "Uspjesno izvrseno (uz Myster Muscolo!!!)";
?>
<a href="citaj.php">Procitaj podatke</a>
And when user click on the link above (procitaj podatke) it should display this page:citaj.php
<?php
$file="podaci.txt";
$open=fopen($file,"r");
print(fread($open,10000));
?>
First 2 pages work perfectly but i dont know how to display list of names on last page citaj.php...
plss helpp!!!

<li></li></ul>
i can give you code that I have creatred and it stores data from form into txt (names) and it stores them each one next to one before : mikejohnpeterpatrickclarasony
And it should look like :
mike
john
peter
patrick
clara
sony
And in a next page it should dysplay everything from that txt file in this form:
- Mike
John
Peter
Patrick
clara
sony
and so on...(if i add more names it would display them
this is a code that i created :
html page aka form page : htmldio.html:
<body>
<form action="podaci.php" method="post">
Ime:
<input type="text" name="ime" align="left" />
<input type="submit" value="Dodaj ime
</form>
</body>
php page for inserting data (ime) into txt : podaci.php:
<?php
$ime=$_POST['ime'];
$file="podaci.txt";
$open=fopen($file,"a") or die ("Nisam otvorio fajl sorry do mene je ;(");
fwrite($open,$ime."\r\n");
fclose($open);
echo "Uspjesno izvrseno (uz Myster Muscolo!!!)";
?>
<a href="citaj.php">Procitaj podatke</a>
And when user click on the link above (procitaj podatke) it should display this page:citaj.php
<?php
$file="podaci.txt";
$open=fopen($file,"r");
print(fread($open,10000));
?>
First 2 pages work perfectly but i dont know how to display list of names on last page citaj.php...
plss helpp!!!