Warning: Illegal string offset
プログラミング&teratail超初心者です。
また質問させていただくのですが、今度はWarning: Illegal string offsetというエラーが出ました。
調べてもイマイチわからなかったのでどういうものなのか、対処法を教えてほしいです。
エラー
Warning: Illegal string offset 'number' in /var/www/www/room.php on line 87
S
Warning: Illegal string offset 'user_name' in /var/www/www/room.php on line 88
S
Warning: Illegal string offset 'text' in /var/www/www/room.php on line 92
S
<?php require('dbconnect.php'); $room_id = $_GET['room_id']; $id = filter_input(INPUT_POST,'id'); $thread_number = filter_input(INPUT_POST,'thread_number'); // ナンバー $number = $db->prepare('SELECT COUNT(*)+1 FROM comments WHERE room_id = '. $room_id .''); $result = $number->execute(); if (!empty($_POST)) { // エラーの確認 if ($_POST['text'] == '') { $error['text'] = 'blank'; } if ($_POST['user_name'] == '') { $error['user_name'] = 'blank'; } if (empty($error)) { $_SESSION['join'] = $_POST; header('Location: http://192.168.2.52/room.php?room_id='.$id.''); exit(); } } //DB挿入 if (!empty($_POST)) { $message = $db->prepare("INSERT INTO comments (room_id, thread_number, number, text, user_name, modified, created) VALUES (?, ?, ?, ?, ?, now(), now())"); if (empty($_POST['thread_number'])) { $threadNumber = null; } else { $threadNumber = $_POST['thread_number']; } $res = $message->execute( array( $room_id, $threadNumber, $result, $_POST['text'], $_POST['user_name']) ); header('Location: http://192.168.2.52/room.php?room_id='.$id.''); exit(); } // コメント表示 $posts = $db->prepare('SELECT number, text, user_name FROM comments WHERE room_id = '. $room_id .' ORDER BY created ASC'); $posts->execute(); // 返信 ?> <!DOCTYPE html> <html lang="ja" dir="ltr"> <head> <meta charset="utf-8"> <title>掲示板</title> <link rel="stylesheet" href="roomStyle.css"> </head> <body> <div id="room"> <header> <a href="index.php"><h1><span>掲示板**ボールドテキスト**</span></h1></a> <div align="right"><?php echo date('Y/m/d') ?></div> </header> <div> <?php foreach ((array)$posts as $post): ?> <table> <tr class="tr"> <th><?php echo htmlspecialchars($post['number'], ENT_QUOTES); ?></th> <th><?php echo htmlspecialchars($post['user_name'], ENT_QUOTES); ?></th> <?php echo "<br>"; ?> </tr> </table> <p class="p"><?php echo htmlspecialchars($post['text'], ENT_QUOTES); ?></p> <?php echo "<br>"; ?> <?php endforeach; ?> </div> <div class="comment-Registration"> <form action="" method="post" /> <h3>コメント登録</h3> <ul> <li> <input type="hidden" name="room_id" value="<?php echo $room_id; ?>" /> <label for="number">返信</label> <input type="hidden" name="number" /> <?php echo htmlspecialchars(filter_input(INPUT_POST,'number'), ENT_QUOTES); ?> <input type="number" name="thread_number" placeholder="番号" size="30" min="1" max="99" /> <?php echo htmlspecialchars(filter_input(INPUT_POST,'thread_number'), ENT_QUOTES); ?> </li> <li> <label for="text">コメント</label> <textarea type="text" name="text" placeholder="入力してください" cols="100" rows="10" value="<?php echo htmlspecialchars(filter_input(INPUT_POST,'text'), ENT_QUOTES); ?>" ></textarea> <?php if ($error['text'] != 'blank'): ?> <p class="error">* 必ず入力してください</p> <?php endif; ?> </li> <li> <label for="user_name">名前</label> <input type="text" name="user_name" size="40" placeholder="名前です" value="<?php echo htmlspecialchars(filter_input(INPUT_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> </body> </html>