Jump to content

"fopen" function


wattsup88

Recommended Posts

Hey guys! I cant get the fopen function to work in this block of code... Any idea why? or any alternative ideas... Just trying to create a newsfeed....

 

<?php

//this should all go into one file. I would name it addnews.php
if($HTTP_POST_VARS['submit']) {
    if($HTTP_POST_VARS['password'] == 'pass') {
        if(!$HTTP_POST_VARS['name']) {
            echo "You must enter a name";
            exit;
        }
        if(!$HTTP_POST_VARS['news']) {
            echo "You must enter some news";
            exit;
        }
        if(strstr($HTTP_POST_VARS['name'],"|")) {
            echo "Name cannot contain the pipe symbol - |";
            exit;
        }
        if(strstr($HTTP_POST_VARS['news'],"|")) {
            echo "News cannot contain the pipe symbol - |";
            exit;
        }
        $fp = fopen('news.txt','a');
        if(!$fp) {
            echo "Error opening file!";
            exit;
        }
        $line = date("m.d.y") . "|" . $HTTP_POST_VARS['name'];
        $line .= "|" . $HTTP_POST_VARS['news'];
        $line = str_replace("\r\n","<BR>",$line);
        $line .= "\r\n";
        fwrite($fp, $line);
        if(!fclose($fp)) {
            echo "Error closing file!";
            exit;
        }        
    } else {
        echo "Bad Password";
    }
}

?>

Link to comment
Share on other sites

By "work" i mean that this block always returns true and therefore echos the message and exits. I want this block to return false (see code above).

 

if(!$fp) {
            echo "Error opening file!";
            exit;
        }

 

Also i believe the file is writable but how do i tell... I right-clicked and check and the "read-only" box is not checked if thats what you mean... oh and the folder on my server is writable of course...

 

and yes i know about the $_POST thing i copied and pasted some old code and i havent replaced it... Thanks for bringing that to my attention though  :)

 

 

Sorry to be so noobish but i have never dealt with this function before...

Thanks for the help already and

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.