using FOPEN

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
misfitxnet
Forum Newbie
Posts: 14
Joined: Mon May 11, 2009 8:40 am

using FOPEN

Post 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?
Last edited by Benjamin on Mon May 11, 2009 10:14 am, edited 1 time in total.
Reason: Added [code=php] tags.
Yossarian
Forum Contributor
Posts: 101
Joined: Fri Jun 30, 2006 4:43 am

Re: using FOPEN

Post by Yossarian »

Line 8 does not end in a semi-colon, add one.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: using FOPEN

Post 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
Post Reply