Writing to a text file from PHP
| From: | Jack Pappas \(AIM: 'Prof Quail'\) | Date: | Thu, 24 Aug 2000 00:17:56 +0000 |
| Subject: | Writing to a text file from PHP | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-13267@lists.php.net to get a copy of this message | ||
Hey-
I'm fairly new to PHP, I'm an ASP programmer by nature, but I figured
that it would be useful to know PHP as well. With that said, here's my
question. Can anyone help me with writing to a text file from PHP? I
rewrote a page I had as ASP (worked fine) to PHP (got some errors). The
error I've been getting is only labeled (parse error). Can anyone give
me pointers on how to do this, (or better) debug it another way besides
using a web browser? Thanks, -Jack
P.S. I will include my code below if that will help anyone answer my
question.
<!--Beginning of Code-->
<html>
<head>
<title>Request Test Page</title>
</head>
<body>
<? $Name=$HTTP_POST_VARS["myname"];
$Grade=$HTTP_POST_VARS["grade"];
$School=$HTTP_POST_VARS["school"];
$Email=$HTTP_POST_VARS["myemail"];
$MyRequest=$HTTP_POST_VARS["myrequest"];
$Comments=$HTTP_POST_VARS["mycomments"];
$Newsletter=$HTTP_POST_VARS["newsletter"];
$FormCompleted=true;
?>
<? if ($Name=="")
{
$FormCompleted=false;
}
if ($Grade=="")
{
$FormCompleted=false;
}
if ($School=="")
{
$FormCompleted=false;
}
if ($Email=="")
{
$FormCompleted=false;
}
if ($MyRequest=="")
{
$FormCompleted=false;
}
if ($FormCompleted==false)
{
?>
<FORM ACTION="requests.php" METHOD="POST">
<P><CENTER><FONT SIZE="+3">Requests Test
Page</FONT></CENTER></P>
<P><FONT SIZE="+1"><FONT COLOR="Red"><B><I>You
have not completely
filled out this form.</I></B></FONT></FONT></P>
<P><TABLE BORDER="1" CELLSPACING="2" CELLPADDING="0">
<TR>
<TD>
<TABLE WIDTH="75%" BORDER="0" CELLSPACING="2"
CELLPADDING="0">
<TR>
<TD WIDTH="153">
<B>Name:</B></TD>
<TD WIDTH="485">
<INPUT NAME="myname" TYPE="text" SIZE="64">
</TD>
</TR>
<TR>
<TD WIDTH="153">
<B>Grade (if applicable):</B></TD>
<TD WIDTH="485">
<INPUT TYPE="radio" VALUE="9" NAME="grade">9
<INPUT TYPE="radio" VALUE="10" NAME="grade">10 <INPUT
TYPE="radio"
VALUE="11" NAME="grade">11 <INPUT TYPE="radio"
VALUE="12"
NAME="grade">12
<INPUT TYPE="radio" VALUE="13"
NAME="grade">Other</TD>
</TR>
<TR>
<TD WIDTH="153">
<B>What school you attend:</B></TD>
<TD WIDTH="485">
<INPUT TYPE="radio" VALUE="1"
NAME="school">WWPHS-North
<INPUT TYPE="radio" VALUE="2" NAME="school">WWPHS-South
<INPUT TYPE="radio" VALUE="3" NAME="school">Other in
WWP <INPUT TYPE="radio" VALUE="4"
NAME="school">Other</TD>
</TR>
<TR>
<TD WIDTH="153">
<B>E-Mail Address:</B></TD>
<TD WIDTH="485">
<INPUT NAME="myemail" TYPE="text" SIZE="64">
</TD>
</TR>
<TR>
<TD WIDTH="153">
<B>Request:</B></TD>
<TD WIDTH="485">
<INPUT NAME="myrequest" TYPE="text" SIZE="64">
</TD>
</TR>
<TR>
<TD WIDTH="153">
<B>Comments:</B></TD>
<TD WIDTH="485">
<TEXTAREA NAME="mycomments" ROWS="2" COLS="60"
></TEXTAREA></TD>
</TR>
</TABLE><TABLE WIDTH="75%" BORDER="0" CELLSPACING="2"
CELLPADDING="0">
<TR>
<TD WIDTH="100%">
<B><INPUT TYPE="checkbox" NAME="newsletter">Check
here if you would like to be added to the Pirate
Newsletter!</B></TD>
</TR>
</TABLE><TABLE WIDTH="75%" BORDER="0" CELLSPACING="2"
CELLPADDING="0">
<TR>
<TD WIDTH="489">
<INPUT NAME="submitbutton" TYPE="submit"
VALUE="Submit"></TD>
<TD WIDTH="489">
<INPUT NAME="name" TYPE="reset"
VALUE="Reset"></TD>
</TR>
</TABLE></TD>
</TR>
</TABLE></FORM>
<? }
else
{
?>
<FONT SIZE="+2">Your request was completed successfully.</FONT><P>
<A HREF="requests.html">Click here</A> to make another request, or <A
HREF="index.html">here</A> to return to the main page.
<? if ($School=="1")
{
$SchoolName="WWPHS-North";
}
else
if ($School=="2")
{
$then;
$SchoolName="WWPHS-South";
}
else
if ($School=="3")
{
$then;
$SchoolName="Other in WWP";
}
else
if ($School=="4")
{
$then;
$SchoolName="Other";
}
else
{
$SchoolName="Unknown (Form Error)";
}
if ($Grade=="13")
{
$PrintGrade="Other Grade";
}
else
{
$PrintGrade=$Grade;
} ?>
<? $CreateObject["Scripting.FileSystemObject"]
$filesys $OpenTextFile["D:\website\requests.txt",8,0];
$myrequestfile.$WriteLine[$Name];
$myrequestfile.$WriteLine[$Grade];
$myrequestfile.$WriteLine[$SchoolName];
$myrequestfile.$WriteLine[$Email];
$myrequestfile.$WriteLine[$MyRequest];
$myrequestfile.$WriteLine[$Comments];
$myrequestfile.$WriteBlankLines[1];
$myrequestfile.$Close;
?>
<?
if ($Newsletter=="true")
{
$CreateObject["Scripting.FileSystemObject"]
$filesysob $OpenTextFile["D:\website\newsletter.txt",8,0];
$newsletterfile.$WriteLine[$Name];
$newsletterfile.$WriteLine[$Email];
$newsletterfile.$WriteBlankLines[1];
$newsletterfile.$Close;
} ?>
<? } ?>
</body>
</html>
<!--End of Code-->