前提・実現したいこと
プログラミング&teratail超初心者です。
PHPで掲示板を作っているのですが、Notice: Undifined indexというのが出てどうすれば良いか分かりません。
発生している問題・エラーメッセージ
Notice: Undefined index: id in /var/www/www/index.php on line 83
<br /><b>Notice</b>: Undefined index: title in <b>/var/www/www/index.php</b> on line <b>86</b><br />
Notice: Undefined variable: error in /var/www/www/index.php on line 87
<br /><b>Notice</b>: Undefined index: user_name in <b>/var/www/www/index.php</b> on line <b>94</b><br />
Notice: Undefined variable: error in /var/www/www/index.php on line 96
該当のソースコード
<?php var_dump($_POST); require_once('dbconnect.php'); if (!empty($_POST)) { $statement = $db->prepare('INSERT INTO rooms SET title=?, user_name=?, modified=NOW(), created=NOW()'); $statement->execute( array( $_POST['title'], $_POST['user_name']) ); header('Location: http://192.168.2.52/index.php'); exit(); } $posts = $db->query('SELECT id, title, user_name, modified FROM rooms ORDER BY modified DESC'); ?> <!DOCTYPE html> <html lang="ja" dir="ltr"> <head> <meta charset="utf-8"> <title>掲示板</title> <link rel="stylesheet" href="stylesheet.css"> </head> <body> <div id="wrap"> <header> <a href="index.php"><h1>掲示板</h1></a> <div align="right"><?php echo date('Y/m/d') ?></div> </header> <div class="contents"> <div class="rooms-list"> <table> <tr> <tr><th align="left">タイトル</th> <th align="right">ルーム作成者</th> <th align="right">最終投稿日</th></tr> </tr> <?php foreach ($posts as $post): ?> <tr class="room-detail"> <td align="left"><a href="room.php?room_id=<?php echo htmlspecialchars($post['id'], ENT_QUOTES); ?>"><?php echo htmlspecialchars($post['title'], ENT_QUOTES); ?></a></td> <td align="right"><?php echo htmlspecialchars($post['user_name'], ENT_QUOTES); ?></td> <td align="right"><?php echo htmlspecialchars($post['modified'], ENT_QUOTES) ?></td> </tr> <?php endforeach; ?> </table></div> </body> </html></div> <div class="room-Registration"> <form action="index.php" method="post" > <h3>ルーム登録</h3> <ul> <input type="hidden" name="id" /> <?php echo htmlspecialchars($_POST['id'], ENT_QUOTES); ?> <li align="left"> <label align="left">ルーム名</label> <input type="text" name="title" size="35" maxlength="20" /> <?php echo htmlspecialchars($_POST['title'], ENT_QUOTES); ?> <?php if ($error['title'] == 'blank'): ?> <p class="error">* 必ず入力してください</p> </li> <?php endif; ?> <li align="left"> <label align="left">名前</label> <input type="text" name="user_name" size="35" maxlength="20" /> <?php echo htmlspecialchars($_POST['user_name'], ENT_QUOTES); ?> <input type="submit" value="登録" class="square_btn"/> <?php if ($error['user_name'] == 'blank'): ?> <p class="error">* 必ず入力してください</p> <?php endif; ?> </li> </ul> </form> </div> </div>
回答2件
あなたの回答
tips
プレビュー