Page 1 of 1

using FOPEN

Posted: Mon May 11, 2009 8:42 am
by misfitxnet
Hello
I am writing a script that writes form input to a text file.
I get this error:
Parse error: syntax error, unexpected T_VARIABLE in d:\hshome\c239198\local54memberforum.com\submitcomment.php on line 8

And I am using this code:

Code: Select all

 
<html>
<head>
<title>Local 54 Member Forum</title>
<?php
$name=$_POST['name'];
$comment = $_POST['comment'];
$output = $name."\t".$comment
$fp = fopen("d:\hshome\c239198\local54memberforum.com\comment.txt", 'ab');
flock($fp, LOCK_EX);
if (!$fp) {
   echo <p><strong> Your order could not be processed at this time.</strong></p>;
   exit;
}
fwrite($fp, $output, strlen($output));
flock($fp, LOCK_UN);
fclose($fp);
echo <p>Submitted</p>
?>
</body>
</html>
 
Does anyone see any errors?

Re: using FOPEN

Posted: Mon May 11, 2009 11:54 am
by Yossarian
Line 8 does not end in a semi-colon, add one.

Re: using FOPEN

Posted: Mon May 11, 2009 12:01 pm
by Mark Baker
And escape slashes if you're using windows format directory paths, especially inside double quotes

Code: Select all

$fp = fopen("d:\\hshome\\c239198\\local54memberforum.com\\comment.txt", 'ab');
or use single quotes

Code: Select all

$fp = fopen('d:\hshome\c239198\local54memberforum.com\comment.txt', 'ab');
or use Unix format

Code: Select all

$fp = fopen("/hshome/c239198/local54memberforum.com/comment.txt", 'ab');
for better compatibility