この回答は、将来同様の質問をする可能性がある人のためのものです。
データベースなしでコメントを追加することは非現実的ですが、実行可能です。以下は、あなたがそれについて行く方法です。
ステップ 1: ファイルを作成し、comment.php のように .php 拡張子を付けて保存します ステップ 2. 通常の html フォームを作成し、フォーム メソッド = "post" とフォーム アクションをファイルの名前に設定します。 php」
<h3> Add a comment here </h3>
<form action="comment.php" method="post">
<label for="name">Name:</label>
<input type="text" name="yourname"><br>
<label for="name">Comment:</label>
<textarea name="comment" id="comment" cols="30" rows="10"></textarea>
<input type="submit" value="submit">
</form>
` ステップ 3. 同じファイル comment.php 内に php スクリプトを記述して、フォームからのデータを処理します。スクリプトをphpタグで囲むことを忘れないでください
<?php
$yourname = $_POST['yourname'];
$comment = $_POST['comment'];
// format the comment data into how you want it to be displayed on the page
$data = $yourname . "<br>" . $comment . "<br><br>";
//Open a text file for writing and save it in a variable of your chosen.
//Remember to use "a" not "w" to indicate write. Using 'w' will overwrite
// any existing item in the file whenever a new item is written to it.
$myfile = fopen("comment.txt", "a");
//write the formatted data into the opened file and close it
fwrite($myfile, $data);
fclose($myfile);
// Reopen the file for reading, echo the content and close the file
$myfile = fopen("comment.txt", "r");
echo fread($myfile,filesize("comment.txt"));
?>