TeamPhotoshop
Reviews, updates and in depth guides to your favourite mobile games - AppGamer.com
Forum Home Latest Posts Search Help Subscribe

PHP and fwrite function

Page: 1 Reply
May 31st 2003#105925 Report
Member since: Dec 17th 2002
Posts: 150
I've been making a website lately, and have just added a registration form to enter a competition. What i want is to add the users details from the form into a text file. Everything's working as normal(the form emails the info to me after going through a processing page). Anyway - Onto my problem. I've added the following code so it will write the form information into the text file:
[PHP] $filename = 'complist.txt';
$content = "username : $username - First Name : $name1 - Last Name : $name2 - e-mail address : $email\n";
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
print "Cannot open file ($filename)";
exit;
}

if (!fwrite($handle, $somecontent)) {
print "Cannot write to file ($filename)";
exit;
}

print "Success, wrote ($content) to file ($filename)";

fclose($handle);

} else {
print "The file $filename is not writable";
}
?> [/PHP]

and i get the error "Cannot Write To File(complist.txt)"

I've CHMOD'd the text file to 666, and it didn't work...and it doesn't work on 777 either. Anyone know the problem?
Reply with Quote Reply
May 31st 2003#105933 Report
Member since: Mar 24th 2002
Posts: 3114
don't use 's, use "s in the PHP code.
And why do you have that if(is_writable) there?
It's one file, and it won't change, right?
You don't need that...

and it should be 777 or 0777.
Reply with Quote Reply
May 31st 2003#105971 Report
Member since: Jun 30th 2001
Posts: 447
This is off subject but Paavo, why do you say don't use 's, use "s instead? I though it was better to use 's if the string doesn't need to be processed which in the end saves proccessing time. Using "s when a string or variable doesn't need to be processed wastes time.
Reply with Quote Reply
Jun 1st 2003#106071 Report
Member since: Mar 24th 2002
Posts: 3114
oh..I stand corrected I guess.
I just always use "s for the PHP, and 's for the crap it echoes out.
You're the coding guru, so I guess you know better. :D
Reply with Quote Reply
Jun 9th 2003#107499 Report
Member since: Jun 9th 2003
Posts: 8
[PHP]$filename = 'complist.txt';
$content = "username : $username - First Name : $name1 - Last Name : $name2 - e-mail address : $email\n";
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
print "Cannot open file ($filename)";
exit;
}

if (!fwrite($handle, $content)) {
print "Cannot write to file ($filename)";
exit;
}

print "Success, wrote ($content) to file ($filename)";

fclose($handle);

} else {
print "The file $filename is not writable";
}
?>[/PHP]


You simply had the variable $somecontent in the fwrite, not $content.
Reply with Quote Reply
Jun 9th 2003#107513 Report
Member since: Nov 26th 2001
Posts: 2586
Right on - do we have another php guru here?
Reply with Quote Reply
Jun 9th 2003#107531 Report
Member since: Jun 9th 2003
Posts: 8
I did own the domain "perfectphp.com" ;)
Reply with Quote Reply
Page: 1 Back to top
Please login or register above to post in this forum