php
1<html> 2 3 4 <form action="2-306.php" method="post"> 5 6 7 <input type="text" placeholder="名前" name="name"><br> 8 9 <input type="text" placeholder="コメント" name="coment"><br> 10 11<input type="submit" value="送信"><br> 12 13 <input type="text" placeholder="削除対象番号" name="number"><br> 14 15<input type="submit" value="削除"> 16 17 18</form> 19 20 21</html> 22 23 24<?php 25 26touch('mission_2-3_06.txt'); 27 28 29?> 30 31 32 33 34<?php 35 36 37date_default_timezone_set('Asia/Tokyo'); 38 39$filename = 'mission_2-3_06.txt'; 40 41$lines = file($filename); 42 43$number = 1 + count($lines); 44 45 46?> 47 48 49<?php 50 51 52if(isset($_POST['name']) or isset($_POST['coment']) and empty($_POST['number'])) 53 54 55 56 57{$fp = fopen($filename, "a"); 58 59fwrite($fp, $number."<>".$_POST['name']."<>".$_POST['coment']."<>".date("Y年m月d日 H:i:s"). "\n"); 60 61fclose($fp); 62 63 64 65 66$lines = file($filename); 67 68 69foreach($lines as $line) 70 71{$portion = explode( "<>", $line); 72 73echo "<pre>". $portion[0]." ". $portion[1]." ". $portion[2]." ". $portion[3]." ". $portion[4]. "</pre>" ; 74 75} 76} 77 78 79elseif(empty($_POST['name']) and empty($_POST['coment']) and isset($_POST['number'])) 80{ 81$fq = fopen($filename, "w"); 82 83for ($i = 0; $i !== $POST['number']; $i++) 84 { 85 fwrite($fq, "$lines[$i]"."<br>"); 86 87 foreach($lines as $line) 88 89{$portion = explode( "<>", $line); 90 91echo "<pre>". $portion[0]." ". $portion[1]." ". $portion[2]." ". $portion[3]." ". $portion[4]. "</pre>" ; 92 93} 94 95} 96 97 98}
なにをやっても追記されます。