Noob needs help with filenames

[php]

Thank you for submitting your feedback.

<?php $file2 = fopen("/feedback/counter.txt", 'r'); $num = fgetc($file2); fwrite("http://fwin.co.cc/imgboard/feedback/feedback" . $num . ".txt" , $_POST["Name"] " " . $_POST["fb"] " " . $_POST["userip"] ); fclose("feedback/counter.txt"); fopen("/feedback/counter.txt", 'w'); fwrite("/feedback/counter.txt", $num++); ?>[/php] There's my code, it's supposed to make a "feedback#.txt" file in the /feedback/ directory for every feedback form submitted. The error is Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/a9376970/public_html/imgboard/feedback2.php on line 7. Line 7 is the first fwrite line. I've seen this error a few times before but I can't remember what I did that made it go away.

I’m pretty sure you’re missing a period Different. Look after $_POST[“name”]. I think that’s the problem.

[php]fwrite(“http://fwin.co.cc/imgboard/feedback/feedback” . $num . “.txt” , $_POST[“Name”] " " . $_POST[“fb”] " " . $_POST[“userip”] );[/php]

Should be:

[php]fwrite(“http://fwin.co.cc/imgboard/feedback/feedback” . $num . “.txt” , $_POST[“Name”] . " " . $_POST[“fb”] . " " . $_POST[“userip”] );[/php]

Actually most of that code should not even work.
fopen( $filename, $mode [, $use_include_path = false [, $context ] ] ) - This is ok
fwrite( $handle, $string [, $length ] ) - All your uses are incorrect
fclose( $handle ) - Again your usage is incorrect

[php]

<?php if(file_exists('counter.txt')) $counter=intval(file_get_contents('counter.txt')); else $counter=1; file_put_contents('feedback-'.$counter.'.txt', $_POST["Name"] . " " . $_POST["fb"] . " " . $_POST["userip"] .PHP_EOL); file_put_contents('counter.txt',++$counter) ?>

[/php]

file_get_contents/put_contents are very useful php functions, when you only need 1 read/write of a file.
fopen/fgets/fwrite/fclose are really used when you have huge amount of data in a file and have to chunk read/write, working with binary/flatfile db files, or using some random access system.

and note the ++$counter, not $counter++
there is a big difference, one does the increment before releasing the value, and the other does it it after releasing the value. In this instance it really doesn’t matter as that is as far as the evaluation goes, but in bigger evaluations it makes a huge difference :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service