Ok. I'm a newbie so be nice. I have the following code and I'm trying to write to following attending.txt file and I keep getting permissions denied. An help would be appreciated. if (empty($_GET['name']) || !isset($_GET['attendance'])) echo "<p>You must enter your name and specify whether you will attend! Click your browser's Back button to return to the RSVP form.</p>"; else if ($_GET['attendance'] == "yes" && !is_numeric($_GET['guests'])) echo "<p>Please specify the number of guests who will accompany you! Click your browser's Back button to return to the RSVP form.</p>"; else { if ($_GET['attendance'] == "yes") { $YesFile = fopen("attending.txt", "w"); if (file_put_contents($YesFile, addslashes($_GET['name']) . ", " . $_GET['guests'] . "\r\n", FILE_APPEND)) echo "<p>Thanks for RSVP'ing! We're looking forward to seeing you!</p>"; else $YesFile = fopen("attending.txt", "w"); echo "<p>Cannot save to the $YesFile file.</p>"; } if ($_GET['attendance'] == "no") { $NoFile = "notattending.txt"; if (file_put_contents($NoFile, addslashes($_GET['name']) . "\n", FILE_APPEND)) echo "<p>Thanks for RSVP'ing! Sorry you can't make it!</p>"; else $NoFile = fopen("notattending.txt", "w"); echo "<p>Cannot save to the $NoFile file.</p>"; } } ?>
make sure you have the permission to write to that folder? chmod it to 777 and try it again. and your if-else statement does not have curly brackets {} and that will make the code looks messy
Hi, You are having a permissions error. Try changing the permissions using your control panel or FTP to 777. Thanks imphpguru
Thanks it was the {} problem. I'm getting more errors, but will work through them. Thanks for the suggestions.
i added the curly brackets for u. Try this but dun lose your original copy if (empty($_GET['name']) || !isset($_GET['attendance'])) { echo "<p>You must enter your name and specify whether you will attend! Click your browser's Back button to return to the RSVP form.</p>"; } elseif ($_GET['attendance'] == "yes" && !is_numeric($_GET['guests'])) { echo "<p>Please specify the number of guests who will accompany you! Click your browser's Back button to return to the RSVP form.</p>"; } else { if ($_GET['attendance'] == "yes") { $YesFile = fopen("attending.txt", "w"); if (file_put_contents($YesFile, addslashes($_GET['name']) . ", " . $_GET['guests'] . "\r\n", FILE_APPEND)) { echo "<p>Thanks for RSVP'ing! We're looking forward to seeing you!</p>"; } else { $YesFile = fopen("attending.txt", "w"); echo "<p>Cannot save to the $YesFile file.</p>"; } } elseif ($_GET['attendance'] == "no") { $NoFile = "notattending.txt"; if (file_put_contents($NoFile, addslashes($_GET['name']) . "\n", FILE_APPEND)) { echo "<p>Thanks for RSVP'ing! Sorry you can't make it!</p>"; } else { $NoFile = fopen("notattending.txt", "w"); echo "<p>Cannot save to the $NoFile file.</p>"; } } } PHP:
now I get this error. Warning: file_put_contents() expects parameter 1 to be string, resource given in /opt/iSpaceWeb/jdb06t/html/LIS5364/SendRSVP.php on line 28 Cannot save to the Resource id #4 file.