I'm have a simple form I'm trying to write to a flat file 'data.txt' these simple variables $name, $email, $comments. Once the form is filled out, it submits to itself and explodes the info from data.txt. onto the same page. But it doesn't write the variables to data.txt. It DOES write the the two tabs and <BR> though, just not with the variables. And yes the data.txt file has 777 permissions.
See it here:
http://ulybusch.com/stevoandmelisse/message_board_long.php
NOTE: For testing purposes I created some fake entries on the data.txt file to see that the ReadFromFile function is indeed working.
<?php
/** This function takes 3 arguments, which will be written to an external file. */
function WriteToFile ($name,$email,$comments) {
$TheFile = "data.txt";
$Open = fopen ($TheFile, "a");
if ($Open) {
fwrite ($Open, "$name\t$email\t$comments\n");
fclose ($Open);
$Worked = TRUE;
} else {
$Worked = FALSE;
}
return $Worked;
}
// END of WriteToFile function
/ TESTING - This is what I'm trying to achieve, most recent one first /
echo "<strong>$name</strong>,\n<BR><a href=\"mailto:$email\">$email</a>,\n<BR>$comments\n<BR><BR>";
/** ReadFromFile function, displays info from data.txt */
function ReadFromFile () {
$TheFile = "data.txt";
$Open = fopen ($TheFile, "r");
if ($Open) {
echo "Comments submitted:<P>\n";
$Data = file ($TheFile);
for ($n=0; $n < count($Data); $n++) {
$GetLine = explode("\t",$Data[$n]);
echo ("$GetLine[0]<BR>\n$GetLine[1]<BR>\n$GetLine[2]<BR>\n");
}
fclose ($Open);
echo "<HR><P>\n";
} else {
echo "Unable to read from data.txt!<BR>\n";
}
}
// End of ReadFromFile function
/** Diplays HTML Form stuff */
function CreateForm() {
echo "<FORM ACTION=\"message_board_long.php\" METHOD=POST>\n";
echo "Name: <INPUT TYPE=TEXT NAME=\"name\" SIZE=\"25\">\n<BR>";
echo "Email: <INPUT TYPE=TEXT NAME=\"email\" SIZE=\"25\">\n<BR>";
echo "<BR>\n";
echo "Comments:<BR>\n";
echo "<textarea name=\"comments\" cols=\"40\" rows=\"3\"></textarea><BR><BR>\n";
echo "<INPUT TYPE=HIDDEN NAME=\"BeenSubmitted\" VALUE=\"TRUE\">\n";
echo "<INPUT TYPE=SUBMIT NAME=\"SUBMIT\" VALUE=\"Submit\">\n";
echo "</FORM>\n";
}
// End of CreateForm function
/** Handle Form function */
function HandleForm() {
global $Array;
$CallFunction = WriteToFile ($Array["name"],$Array["email"],$Array["comments"]);
if ($CallFunction) {
echo "Thank you $name, your comment has been submitted<br /><HR>\n";
} else {
echo "Sorry there was a system error<BR>\n";
}
}
// End of HandleForm function
/ $BeenSubmitted = TRUE? /
if ($BeenSubmitted) {
HandleForm();
}
CreateForm();
ReadFromFile();
?>
Any help very much appreciated. 🙂