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 8876723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:16:49+00:00 2026-06-14T19:16:49+00:00

I need to make a comment box using a txt file or anything else

  • 0

I need to make a comment box using a txt file or anything else that can be queried passively, without using a database server. As I’m fairly new to PHP programming the first idea was to use a text file. The code in general to accomplish this, as far as I can think of logically would be :

    <html>
<head></head>
<body>
<form method = "post">
<textarea name = "txt" cols = "25" rows = "5">
Place your comment here ...
</textarea><br><br>
<input type = "submit" value = "Submit" onclick = "<?php
    $com = $_POST["txt"];
    $file = fopen("inrg.txt", "a");
    fwrite($file, "<br>");
    for($i=0; $i <= strlen($com) - 1; $i++)
        {
        fwrite($file, $com[$i]);
        if($i % 37 == 0 && $i != 0)
            fwrite($file, "<br/>");
        }
    fwrite($file, "<br>------------------------------------------");
    fclose($file);
?>">
<br>
</form>
<font face = "Times New Roman"><b><p>Textul introdus este: </p></b></font>
<font face = "Comic Sans MS" color = "red" size = "2" >
<?php
$file = fopen("inrg.txt", "r");
echo fread($file, filesize("inrg.txt"));
fclose($file);
?>
</font>
</body>
</html>

Nothing fancy yet, and it does needs some improvements on the esthetics side. The thing is after I submit something in the comment box, it shows properly but if I do reload in the web browser, the last posted comment it’s posted again as many times as I reload the page.
Also if there’s a way with PHP to make the initial “Place your comment here …” disappear

  • 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-06-14T19:16:50+00:00Added an answer on June 14, 2026 at 7:16 pm

    Here is one way to do it redirecting the page to itself:

    <html>
    <head></head>
    <body>
    <form method="post">
      <textarea name="txt" cols="25" rows="5"></textarea>
      <br><br> <input type="submit" value="Submit" name="submit" />
    
      <?php
      if ( isset( $_POST[ 'submit' ] ) ) {
        $com  = $_POST[ "txt" ];
        $file = fopen( "inrg.txt", "a" );
        fwrite( $file, "<br>" );
        for ( $i = 0; $i <= strlen( $com ) - 1; $i++ ) {
          fwrite( $file, $com[ $i ] );
          if ( $i % 37 == 0 && $i != 0 ) fwrite( $file, "<br/>" );
        }
        fwrite( $file, "<br>------------------------------------------" );
        fclose( $file );
       echo '<script type="text/javascript">window.location ="";</script>'; // Add here
      }
      ?>
    
      <br>
    </form>
    <font face="Times New Roman"><b><p>Textul introdus este: </p></b></font>
    <font face="Comic Sans MS" color="red" size="2">
      <?php
      if (file_exists("inrg.txt")) {
      $file = fopen( "inrg.txt", "r" );
      echo fread( $file, filesize( "inrg.txt" ) );
      fclose( $file );
      }
      ?>
    </font>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to make the top header of a report disappear. The part that
Is there anything I can do to this code to make it more CPU
A while ago I had asked how to make a collapsible comment box like
I have a file that I'm using to log IP addresses for a client.
When I´m using MATLAB, sometimes I feel the need to make comments on some
I need to make a Form class that may or not have a ReCaptcha
I need to make a lot of operations using BigDecimal, and I found having
I often need to make a core function that's used in many places somehow
I need make some action (dump statistical data) before the Dart program ends. The
I need make all of my posts update. I use bulk upload for store,

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.