###前提・実現したいこと
PHPで掲示板を作っています。
掲示板を作成中にに以下のエラーメッセージが発生しました。
###発生している問題・エラーメッセージ
localhost ページは機能していません localhost では現在このリクエストを処理できません。 HTTP ERROR 500
###該当のソースコード
php+html
1<?php 2$dataFile = "bbs.dat"; 3 4function h($s) { 5 return htmlspecialchars($s, ENT_QUOTES, "utf-8"); 6} 7 8if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["message"]) && isset($_POST["user"])) { 9 10 $message = trim($_POST["message"]); 11 $user = trim($_POST["user"]); 12 13 if ($message !== "") { 14 15 $user = ($user === "") ? "名無しさん" : $user; 16 17 $message = str_replace("\t", " ", $message); 18 $user = str_replace("\t", " ", $user); 19 20 $postedAt = date("Y-m-d H:i:s"); 21 22 $newData = $message . "\t" . $user . "\t" . $postedAt . "\n"; 23 24 $fp = fopen($dataFile, "a"); 25 fwrite($fp, $newData); 26 fclose($fp); 27 } 28} 29 30$posts = file($dataFile, FILE_IGNORE_NEW_LINES); 31 32$posts = array_reverse($posts); 33 34?> 35 36<!DOCTYPE html> 37<html> 38<head> 39 <meta charset="utf-8"> 40 <title>簡易掲示板</title> 41 <style> 42 body { 43 background: #e0e0e0; 44 text-align: center; 45 } 46 input[type=text] { 47 width: 300px; 48 padding: 4px; 49 border-radius: 3px; 50 } 51 ul { 52 list-style: none; 53 } 54 </style> 55</head> 56<body> 57 <h1>簡易掲示板</h1> 58 <form action="" method="post"> 59 メッセージ:<input type="text" name="message"> 60 ユーザー名:<input type="text" name="user" style="width: 150px;"> 61 <input type="submit" value="投稿"> 62 </form> 63 <h2>投稿一覧(<?php echo count($posts); ?>件)</h2> 64 <ul> 65 <?php if (count($posts)) : ?> 66 <?php foreach ($posts as $post) : ?> 67 <?php list($message, $user, $postedAt) = explode("\t", $post); ?> 68 <li><?php echo h($message); ?>(<?php echo h($user); ?>-<?php echo h($postedAt); ?>)</li> 69 <?php foreach; ?> 70 <?php else : ?> 71 <li>まだ投稿はありません。</li> 72 <?php endif; ?> 73 </ul> 74</body> 75</html>
###試したこと
課題に対してアプローチしたことを記載してください
###補足情報(言語/FW/ツール等のバージョンなど)
サーバーは正常です
スペルミスだと思うのですが探しても見つからなかったので・・・
回答お願いします!
500エラーはあらゆるエラーの可能性がありますので、まずはサーバーのエラーログを探してみてください。
回答6件
あなたの回答
tips
プレビュー