投稿番号が1から順に着くようにtxtに書き込みたいのですが、1しかつきません。どこが間違っているのでしょうか。$countの部分が1、2...って感じでなるようにしたかったのですがうまくいかないです。
追記 $count = count($ret_array) => $count = count(file($filename))に修正いたしましたが、問題解決していません。よろしくお願いします
html
1 <form method = "post" action = "mission_3-1-1.php"> 2 <input type = "text" name = "name" value = "名前"><br/> 3 <input type = "text" name = "comment" value = "コメント"><br/> 4 <input type = "submit" value = "送信"> 5 </form>
php
1if (isset($_POST["comment"],$_POST["name"])){ 2 $filename = "mission_3-1.txt"; 3 $date = date('Y-m-d H:i:s'); 4 $name = $_POST["name"]; 5 $comment = $_POST["comment"]; 6 if (file_exists($filename)) { 7 $count = count(file($filename))+1; 8 } else { 9 $count = 1; 10 } 11 $newdata = $count . "<>" . $name . "<>" . $comment . "<>" . $date; 12 13 if ($data != ""){ 14 15 $fp = fopen($filename,"a"); 16 fwrite($fp,$newdata."\n"); 17 fclose($fp); 18 19 } 20 $ret_array = file($filename); 21 22 foreach($ret_array as $line){ 23 echo $line."<br>"; 24 } 25 } 26 27