1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP help

Discussion in 'PHP' started by seminolefan, Sep 26, 2008.

  1. #1
    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>";
    }
    }
    ?>
     
    seminolefan, Sep 26, 2008 IP
  2. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #2
    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
     
    ads2help, Sep 26, 2008 IP
  3. imphpguru

    imphpguru Active Member

    Messages:
    439
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #3
    Hi,
    You are having a permissions error. Try changing the permissions using your control panel or FTP to 777.

    Thanks

    imphpguru
     
    imphpguru, Sep 26, 2008 IP
  4. seminolefan

    seminolefan Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks it was the {} problem. I'm getting more errors, but will work through them.

    Thanks for the suggestions.
     
    seminolefan, Sep 27, 2008 IP
  5. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #5
    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:
     
    ads2help, Sep 27, 2008 IP
  6. seminolefan

    seminolefan Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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.
     
    seminolefan, Sep 28, 2008 IP
  7. seminolefan

    seminolefan Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    ads2help

    Thanks for your help. I had the $YesFile variable set incorrectly.

    Thanks
    Seminolefan
     
    seminolefan, Sep 29, 2008 IP