<html>

<head>
  <title>paiza掲示板</title>
  <style type=text/css>
    div#header{background-color:#ffffff;}
  </style>
</head>

<body>
<div class="container">
<div id="header">

<h1>タイトル</h1>

<h2>サブタイトル1</h2>
<form action="bbs.php" method="post" role="form">
  <div class="form-group">
    <label class="control-label">投稿内容</label>
    <input type="text" name="content" class="form-control" placeholder="投稿内容"/>
  </div>
  <button type="submit" class="btn btn-primary">送信</button>
</form>

<h2>サブタイトル2</h2>

<?php
// データベースへ接続
$dbs = "mysql:host=127.0.0.1;dbname=lesson;charset=utf8";
$db_user = "root";
$db_pass = "";
$pdo = new PDO($dbs, $db_user, $db_pass);

// 変数の設定
$content = $_POST["content"];

// データベースへのデータの挿入
$sql  = "INSERT INTO bbs (content, updated_at) VALUES (:content, NOW());";
$stmt = $pdo->prepare($sql);
$stmt -> bindValue(":content", $content, PDO::PARAM_STR);
$stmt -> execute();

// データベースからのデータの取得
$sql = "SELECT * FROM bbs ORDER BY updated_at $order;";
$stmt = $pdo->prepare($sql);
$stmt -> execute();

// 取得したデータをテーブルで表示
?>
<table class="table">
<tr><th>日時</th><th>投稿内容</th></tr>
<?php
while ($row = $stmt -> fetch(PDO::FETCH_ASSOC)) {
?>
    <tr>
    <td><?php echo "$row[updated_at]"; ?></td>
    <td><?php echo "$row[content]"; ?></td>
    </tr>
<?php
}
?>
</table>
</div>
</div>
</body>
</html>
