Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7703239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:24:46+00:00 2026-05-31T23:24:46+00:00

Im trying to create a script that will post a notification stored in a

  • 0

Im trying to create a script that will post a notification stored in a text file when a project is created/updated.
If the project is created it needs to create the file and if the project is being updated it needs to update the existing txt file for it.

So far I’ve got it to create the txt file and update it. However it is only updating it once, if i try to update the file again it just doesn’t do it.

Here’s the code:

function addPost($userID, $content, $date, $featured, $projectID){
    if($projectID != 0){
        $addClass = 'normal';
        $sql1 = "SELECT * FROM `blog` WHERE `projectID` = ".$projectID;
        $query1 = mysql_query($sql1);
        $num_rows1 = mysql_num_rows($query1);
        if($num_rows1 != 0){
            $addClass = 'internalUpdate';
        }
    }else{
        $addClass = 'normal';
    }

    switch($addClass){
    case normal;
        //SQL to get next ID
        $nameQuery = mysql_query("SELECT MAX(ID) FROM `blog`");
        $nameRow = mysql_fetch_array($nameQuery);
        $nextID = $nameRow['MAX(ID)'] + 1;
        //Set Blogname
        $blogName = md5($nextID).'.txt';
        $blogTargetFile = './file/blog/'.$blogName;
        $fileHandle = fopen($blogTargetFile, 'w');
        fwrite($fileHandle, $content);
        fclose($fileHandle);
        $sql2 = "INSERT INTO `blog` (`userID`, `name`, `created`, `featured`, `projectID`) VALUES ('".$userID."', '".$blogName."', '".$date."', '".$featured."', '".$projectID."')";
    break;
    case internalUpdate;
        $sql1 = "SELECT * FROM `blog` WHERE `projectID` = ".$projectID;
        $query1 = mysql_query($sql1);
        $row1 = mysql_fetch_array($query1);
        $blogName = $row1['name'];
        $blogTargetFile = './file/blog/'.$blogName;
        $fileHandle = fopen($blogTargetFile, 'w');
        fwrite($fileHandle, $content);
        fclose($fileHandle);
        $sql2 = "UPDATE `blog` SET `created` = '".$date."' WHERE `ID` = ".$row1['ID'];
    break;
    }
    mysql_query($sql2);
};

An Ideas?

Charles – richini-design.co.uk

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:24:47+00:00Added an answer on May 31, 2026 at 11:24 pm

    Not sure I got it right, but you’re overwriting the file because of the “w” mode used with fopen function.
    Try fopen([filename], "a") to append data.
    See http://fr.php.net/manual/en/function.fopen.php for more infos.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a script that will upload a file to a website.
I have been trying to create a post login script that will change the
I'm trying to create a script that will read text files and then analyse
I'm trying to write a script that will create a user in MediaWiki, so
im trying to create a script that opens a file and replace every 'hola'
I am trying to create a script that will only execute its actions if
I am trying to write a PHP script that will create an HTML form
I'm trying to create a script that will loop through files that have their
I am trying to create a script that will run a program on each
Hey guys, I am trying to create a script that will pull the log's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.