Dear Helper:
I was wondering if anyone could help me with a little problem I have. I am a Gr. 12 student at Holy Cross Secondary and I'm doing a school project... I've been working on this project for a while. I need a form to have a person input scores for the games which are played at our school. This I've already managed to have finished. My biggest problem is that I need the information inputted by user, stored in the variables to be outputted onto a file eg. Sport.html or Sport.txt. I've seen the include function used but im not sure how to write to a file. The file must also keep all it's old entries and evertime the new information is entered it should go at the top. I hope I've made myself clear enough about this problem. If not I'm be more then happy to clarify.
Anyways if anyone could please help I'd be eternally greatful!
Thanks for your time
Jim
P.S. This is the code where it writes to the sport.html or sport.txt file.
<?if ($user == "user" and $pass == "pass" and
$team == true and
$HCS == true and
$OTS == true and
$information == true)
{
CODE TO WRITE TO TEXT FILE GOES HERE
?>
<?
}else{
?>
You have either entered the incorrect login/password, or have not filled in one of the form fields.
<?
}
?>
How do u write to a text file?
Moderator: General Moderators
-
Jimeee_1999
- Forum Newbie
- Posts: 4
- Joined: Tue May 28, 2002 8:33 am
- Johnm
- Forum Contributor
- Posts: 344
- Joined: Mon May 13, 2002 12:05 pm
- Location: Michigan, USA
- Contact:
This will append to the end of a file not the beginning. Maybe someone else can tell you how to do that. I would probably write a script to go and re-organize the list in the file if I had to have the appended items at the top. Hope I helped,
John
John
Code: Select all
<?php
//Open File to append
$new_file=fopen("file_name.txt","a"); // use the letter "a" to append
if (! $new_file)
die("new_file did not open");
fwrite($var_name,"put text/labels in quotes" or put more vars);
fwrite( do this as many times as you like);
//Close File
fclose($new_file);
?>- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
Code: Select all
<?
//EDIT THESE
$filename = "nameoffile.txt";
//STOP EDITING
if ($user == "user" and $pass == "pass" and
$team == true and
$HCS == true and
$OTS == true and
$information == true)
{
$openfile = fopen("$filename", "a");
$what_to_write = "$team"."|"."$HCS"."|"."$OTS"."|"."$information";
fwrite("$openfile", "$what_to_write");
fclose($openfile);
}
?>
<?
}else{
?>
You have either entered the incorrect login/password, or have not filled in one of the form fields.
<?
}
?>Code: Select all
<?
//EDIT THESE
$filename = "nameoffile.txt";
//STOP EDITING
$f_content = file($filename);
$f_content = array_reverse($f_content);
$a_num = count($f_content);
echo "<table><tr><td>Team<td>HCS<td>OTS<td>Information<tr>";
for ($t = 0; $t < $a_num; $t++) {
$f_array = explode("|", $f_contentї$t]);
echo "<td>".$f_arrayї1]."<td>".$f_arrayї2]."<td>".$f_arrayї3]."<td>";
echo "$f_arrayї4]"."<tr>";
}
echo "</table>";
?>if i have mistakes, would some php master please correct me, i realize i probably have a couple
-
Jimeee_1999
- Forum Newbie
- Posts: 4
- Joined: Tue May 28, 2002 8:33 am
Thank you
Great! Thanks!
I really appreciate all of your help.
Jim
I really appreciate all of your help.
Jim