anonymous No title
PHP
<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>課題2-応用</title>
</head>
<body>
<?php
// データベース接続
$dsn = 'mysql:dbname=co_19_266_99sv_coco_com;host=localhost';
$user = 'co-19-266.99sv-c';
$password = 'Lk6BjZYu';
try {

  $dbh = new PDO($dsn, $user, $password, [PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION] );

  //データベースに接続できなかった時
  } catch (PDOException $e) {

    echo "接続失敗: " . $e->getMessage() . "\n";
    exit();
  }

    //テーブル作成
    $stmt = $dbh->query("CREATE TABLE IF NOT EXISTS posts (
      id INT AUTO_INCREMENT PRIMARY KEY,
      name TEXT,
      comment TEXT,
      postDate TEXT,
      new_pass TEXT
      )"
    );

    // 新規投稿
    if($_SERVER["REQUEST_METHOD"] === 'POST') {
      if(isset($_POST["send"]) && isset($_POST["name"]) && isset($_POST["comment"]) && isset($_POST["new_pass"]) && empty($_POST["hidden_editNo"])) {
        if(!empty($_POST["comment"]) && !empty($_POST["new_pass"]) && isset($_POST["send"])) {
          $name = trim($_POST["name"]);
          $comment = trim($_POST["comment"]);
          $send = $_POST["send"];
          $new_pass = trim($_POST["new_pass"]);
          $postDate = date('Y-m-d H:i:s');
          if(empty($name)) { 
            $name = "名無し";
          }
          $stmt = $dbh->prepare("INSERT INTO posts (name,comment,postDate,new_pass) VALUES (:name,:comment,:postDate,:new_pass)");
          $params = array(':name'=>$name,':comment'=>$comment,':postDate'=> $postDate,':new_pass'=> $new_pass);
          $stmt->execute($params);
          header('Location:http://co-19-266.99sv-coco.com/kadai_2-apply.php');
          exit;
        } elseif(empty($_POST["comment"]) && !empty($_POST["new_pass"]) && isset($_POST["send"])) {
          echo "<script>alert('コメントが入力されていません。');</script>";
        } elseif(empty($_POST["new_pass"]) && !empty($_POST["comment"]) && isset($_POST["send"])) {
          echo "<script>alert('パスワードが入力されていません。');</script>";
        }elseif(isset($_POST["send"]) && empty($_POST["comment"]) && empty($_POST["new_pass"])) {
          echo "<script>alert('パスワードとコメントが入力されていません。');</script>";
        }
      }
    }

// 編集
if($_SERVER["REQUEST_METHOD"] === 'POST') {
  if(isset($_POST["edit"]) && isset($_POST["editNo"]) && isset($_POST["edit_pass"])) {
    if(!empty($_POST["editNo"]) && !empty($_POST["edit_pass"])) {
      $edit = $_POST["edit"];
      $editNo = $_POST["editNo"];
      $edit_pass = $_POST["edit_pass"];
      $res = $dbh->query('SELECT * FROM posts');
      foreach( $res as $value ){
        if($editNo == $value['id'] && $edit_pass == $value['new_pass']) {
          $hidden_editNo = $value['id'];
          $edit_name = $value['name'];
          $edit_comment = $value['comment'];
          $edit_ID = $value['new_pass'];
        } elseif ($editNo == $value['id'] && $edit_pass != $value['new_pass']) {
          echo "<script>alert('パスワードが間違っています。');</script>";
        }
    }
   } elseif (empty($_POST["editNo"]) && isset($_POST["edit"]) && !empty($_POST["edit_pass"])) {
        echo "<script>alert('番号を入力してください。');</script>";
   } elseif (empty($_POST["edit_pass"]) && isset($_POST["edit"]) && !empty($_POST["editNo"])) {
        echo "<script>alert('パスワードを入力してください。');</script>";
   }
  } 
}

//編集する値がフォームに表示された後の投稿
if(!empty($_POST["name"]) && !empty($_POST["comment"]) && !empty($_POST["hidden_editNo"])) {
  $name = $_POST["name"];
  $comment = $_POST["comment"];
  $hidden_editNo = $_POST["hidden_editNo"];
  $postDate = date('Y-m-d H:i:s');
  $new_pass = $_POST["new_pass"];
  $res = $dbh->query('SELECT * FROM posts');
  $stmt = $dbh->prepare("UPDATE posts SET name = :name,comment = :comment,postDate =:postDate, new_pass = :new_pass WHERE id = $hidden_editNo");
  $params = array(':name' => $name,':comment'=>$comment,':postDate'=>$postDate,':new_pass'=>$new_pass);
  $stmt->execute($params);
}

// 削除
if($_SERVER["REQUEST_METHOD"] === 'POST') {
  if(isset($_POST["delete"]) && isset($_POST["deleteNo"]) && isset($_POST["delete_pass"])) {
    if(!empty($_POST["deleteNo"]) && !empty($_POST["delete_pass"])) {
      $delete = $_POST["delete"];
      $deleteNo = $_POST["deleteNo"];
      $delete_pass = $_POST["delete_pass"];
      $res = $dbh->query('SELECT * FROM posts');
      foreach( $res as $value ){
        if($deleteNo == $value['id'] && $delete_pass == $value['new_pass']) {
          $stmt = $dbh->prepare("DELETE FROM posts WHERE id =:id");
          $params = array(':id'=> $deleteNo);
          $stmt->execute($params);
          $sql = "ALTER TABLE posts DROP column id";
          $stmt = $dbh->query($sql);
          $sql = "ALTER TABLE posts add id int(11) primary key not null auto_increment first";
          $stmt = $dbh->query($sql);
          $sql = "ALTER TABLE posts AUTO_INCREMENT = 1"; 
          $stmt = $dbh->query($sql);

          header('Location:http://co-19-266.99sv-coco.com/kadai_2-apply.php');
          exit;
        } else if($deleteNo == $value['id'] && $delete_pass != $value['new_pass']) {
            echo "<script>alert('パスワードが間違っています。');</script>";
        }
      }
    } elseif(empty($_POST["deleteNo"]) && isset($_POST["delete"]) && !empty($_POST["delete_pass"])) {
        echo "<script>alert('番号を入力してください。');</script>";
    } elseif(empty($_POST["delete_pass"]) && isset($_POST["delete"]) && !empty($_POST["deleteNo"])) {
        echo "<script>alert('パスワードを入力してください。');</script>";
    }
  }
}
?>

<!-- html記述 -->
  <h1>簡易掲示板</h1>
  <p>-------------------------------------------------------------------------------</p>
  <!-- 投稿フォーム -->
  <form action = "" method = "post">
  <!-- 編集モード用 のinput-->
  <input type = "hidden" name = "hidden_editNo" value = "<?php if(isset($hidden_editNo)) {echo $hidden_editNo;}?>">
  <p>名前:
    <input type = "text" name = "name" value = "<?php if(isset($edit_name)) {echo $edit_name;}?>">
  </p>
  <p>コメント:
    <textarea name = "comment"><?php if(isset($edit_comment)) {echo $edit_comment;}?></textarea>
  </p>
  <p>パスワードを入力してください:
    <input type = "password" name = "new_pass" value="<?php if(isset($edit_ID)) {echo $edit_ID;}?>">
  </p>
  <input type = "submit" name = "send" value = "投稿">
  </form>
  <p>-------------------------------------------------------------------------------</p>
  <!-- 編集フォーム -->
  <form action = "" method = "post">
  <p>編集したい番号を入力してください:
    <select name= "editNo">  
      <option value="未選択">選択してください</option>
      <?php 
      $sql = 'SELECT * FROM posts';
      $stmt = $dbh->query($sql);
      $stmt-> execute();
      $cnt = $stmt->rowCount();
      echo $cnt;
        for ($i = 1; $i <= $cnt; $i++) {
          echo "<option value = '{$i}'>{$i}</option>";
        }
        if(empty($cnt)) {
          echo "<option disabled value = '{$i}'></option>";
        }
      ?>
    </select>
  </p>
  <p>パスワードを入力してください:
    <input type = "password" name = "edit_pass">
  </p>
  <input type = "submit" name = "edit" value = "編集">
  </form>
  <p>-------------------------------------------------------------------------------</p>
  <!-- 削除フォーム -->
  <form action = "" method = "post" onSubmit="return check()">
  <p>削除したい番号を入力してください:
    <select name= "deleteNo">  
      <option value="未選択">選択してください</option>
      <?php 
      $sql = 'SELECT * FROM posts';
      $stmt = $dbh->query($sql);
      $stmt-> execute();
      $cnt = $stmt->rowCount();
      echo $cnt;
        for ($i = 1; $i <= $cnt; $i++) {
          echo "<option value = '{$i}'>{$i}</option>";
        }
        if(empty($cnt)) {
          echo "<option disabled value = '{$i}'></option>";
        }
      ?>
    </select>
  </p>
  <p>パスワードを入力してください:
    <input type = "password" name = "delete_pass">
  </p>
  <!-- 削除確認ダイアログ -->
  <script type="text/javascript">
    function check(){
      if(window.confirm('本当に削除しますか?')){
       return true;
     }else{
       window.alert('キャンセルされました');
       return false;
     }
   }
  </script>
  <input type = "submit" name = "delete" value = "削除" >
  </form>
  <p>-------------------------------------------------------------------------------</p>
  <!-- 投稿一覧表示 -->
  <h2>投稿一覧(
    <?php
      $sql = 'SELECT * FROM posts';
      $stmt = $dbh->query($sql);
      $stmt-> execute();
      $cnt = $stmt->rowCount();
      echo $cnt;
    ?>
    件)</h2>
  <?php
   $sql = 'SELECT * FROM posts';
   $stmt = $dbh->query($sql);
   $stmt-> execute();
     $res = $dbh-> query('SELECT * FROM posts');
       foreach($res as $value) {
         echo $value['id']."\t";
         echo $value['name']."\t";
         echo $value['comment']."\t";
         echo $value['postDate'];
         echo "<br>";
         echo "<p>---------------------------------------------------------------</p>";
       }
  
  ?>
  <p>-------------------------------------------------------------------------------</p>
</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>課題2-応用</title>
</head>
<body>
<?php
// データベース接続
$dsn = 'mysql:dbname=*******;host=localhost';
$user = '********';
$password ='*******';
try {

  $dbh = new PDO($dsn, $user, $password, [PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION] );

  //データベースに接続できなかった時
  } catch (PDOException $e) {

    echo "接続失敗: " . $e->getMessage() . "\n";
    exit();
  }

    //テーブル作成
    $stmt = $dbh->query("CREATE TABLE IF NOT EXISTS posts (
      id INT AUTO_INCREMENT PRIMARY KEY,
      name TEXT,
      comment TEXT,
      postDate TEXT,
      new_pass TEXT
      )"
    );

    // 新規投稿
    if($_SERVER["REQUEST_METHOD"] === 'POST') {
      if(isset($_POST["send"]) && isset($_POST["name"]) && isset($_POST["comment"]) && isset($_POST["new_pass"]) && empty($_POST["hidden_editNo"])) {
        if(!empty($_POST["comment"]) && !empty($_POST["new_pass"]) && isset($_POST["send"])) {
          $name = trim($_POST["name"]);
          $comment = trim($_POST["comment"]);
          $send = $_POST["send"];
          $new_pass = trim($_POST["new_pass"]);
          $postDate = date('Y-m-d H:i:s');
          if(empty($name)) { 
            $name = "名無し";
          }
          $stmt = $dbh->prepare("INSERT INTO posts (name,comment,postDate,new_pass) VALUES (:name,:comment,:postDate,:new_pass)");
          $params = array(':name'=>$name,':comment'=>$comment,':postDate'=> $postDate,':new_pass'=> $new_pass);
          $stmt->execute($params);
          header('Location:http://co-19-266.99sv-coco.com/kadai_2-apply.php');
          exit;
        } elseif(empty($_POST["comment"]) && !empty($_POST["new_pass"]) && isset($_POST["send"])) {
          echo "<script>alert('コメントが入力されていません。');</script>";
        } elseif(empty($_POST["new_pass"]) && !empty($_POST["comment"]) && isset($_POST["send"])) {
          echo "<script>alert('パスワードが入力されていません。');</script>";
        }elseif(isset($_POST["send"]) && empty($_POST["comment"]) && empty($_POST["new_pass"])) {
          echo "<script>alert('パスワードとコメントが入力されていません。');</script>";
        }
      }
    }

// 編集
if($_SERVER["REQUEST_METHOD"] === 'POST') {
  if(isset($_POST["edit"]) && isset($_POST["editNo"]) && isset($_POST["edit_pass"])) {
    if(!empty($_POST["editNo"]) && !empty($_POST["edit_pass"])) {
      $edit = $_POST["edit"];
      $editNo = $_POST["editNo"];
      $edit_pass = $_POST["edit_pass"];
      $res = $dbh->query('SELECT * FROM posts');
      foreach( $res as $value ){
        if($editNo == $value['id'] && $edit_pass == $value['new_pass']) {
          $hidden_editNo = $value['id'];
          $edit_name = $value['name'];
          $edit_comment = $value['comment'];
          $edit_ID = $value['new_pass'];
        } elseif ($editNo == $value['id'] && $edit_pass != $value['new_pass']) {
          echo "<script>alert('パスワードが間違っています。');</script>";
        }
    }
   } elseif (empty($_POST["editNo"]) && isset($_POST["edit"]) && !empty($_POST["edit_pass"])) {
        echo "<script>alert('番号を入力してください。');</script>";
   } elseif (empty($_POST["edit_pass"]) && isset($_POST["edit"]) && !empty($_POST["editNo"])) {
        echo "<script>alert('パスワードを入力してください。');</script>";
   }
  } 
}

//編集する値がフォームに表示された後の投稿
if(!empty($_POST["name"]) && !empty($_POST["comment"]) && !empty($_POST["hidden_editNo"])) {
  $name = $_POST["name"];
  $comment = $_POST["comment"];
  $hidden_editNo = $_POST["hidden_editNo"];
  $postDate = date('Y-m-d H:i:s');
  $new_pass = $_POST["new_pass"];
  $res = $dbh->query('SELECT * FROM posts');
  $stmt = $dbh->prepare("UPDATE posts SET name = :name,comment = :comment,postDate =:postDate, new_pass = :new_pass WHERE id = $hidden_editNo");
  $params = array(':name' => $name,':comment'=>$comment,':postDate'=>$postDate,':new_pass'=>$new_pass);
  $stmt->execute($params);
}

// 削除
if($_SERVER["REQUEST_METHOD"] === 'POST') {
  if(isset($_POST["delete"]) && isset($_POST["deleteNo"]) && isset($_POST["delete_pass"])) {
    if(!empty($_POST["deleteNo"]) && !empty($_POST["delete_pass"])) {
      $delete = $_POST["delete"];
      $deleteNo = $_POST["deleteNo"];
      $delete_pass = $_POST["delete_pass"];
      $res = $dbh->query('SELECT * FROM posts');
      foreach( $res as $value ){
        if($deleteNo == $value['id'] && $delete_pass == $value['new_pass']) {
          $stmt = $dbh->prepare("DELETE FROM posts WHERE id =:id");
          $params = array(':id'=> $deleteNo);
          $stmt->execute($params);
          $sql = "ALTER TABLE posts DROP column id";
          $stmt = $dbh->query($sql);
          $sql = "ALTER TABLE posts add id int(11) primary key not null auto_increment first";
          $stmt = $dbh->query($sql);
          $sql = "ALTER TABLE posts AUTO_INCREMENT = 1"; 
          $stmt = $dbh->query($sql);

          header('Location:http://co-19-266.99sv-coco.com/kadai_2-apply.php');
          exit;
        } else if($deleteNo == $value['id'] && $delete_pass != $value['new_pass']) {
            echo "<script>alert('パスワードが間違っています。');</script>";
        }
      }
    } elseif(empty($_POST["deleteNo"]) && isset($_POST["delete"]) && !empty($_POST["delete_pass"])) {
        echo "<script>alert('番号を入力してください。');</script>";
    } elseif(empty($_POST["delete_pass"]) && isset($_POST["delete"]) && !empty($_POST["deleteNo"])) {
        echo "<script>alert('パスワードを入力してください。');</script>";
    }
  }
}
?>

<!-- html記述 -->
  <h1>簡易掲示板</h1>
  <p>-------------------------------------------------------------------------------</p>
  <!-- 投稿フォーム -->
  <form action = "" method = "post">
  <!-- 編集モード用 のinput-->
  <input type = "hidden" name = "hidden_editNo" value = "<?php if(isset($hidden_editNo)) {echo $hidden_editNo;}?>">
  <p>名前:
    <input type = "text" name = "name" value = "<?php if(isset($edit_name)) {echo $edit_name;}?>">
  </p>
  <p>コメント:
    <textarea name = "comment"><?php if(isset($edit_comment)) {echo $edit_comment;}?></textarea>
  </p>
  <p>パスワードを入力してください:
    <input type = "password" name = "new_pass" value="<?php if(isset($edit_ID)) {echo $edit_ID;}?>">
  </p>
  <input type = "submit" name = "send" value = "投稿">
  </form>
  <p>-------------------------------------------------------------------------------</p>
  <!-- 編集フォーム -->
  <form action = "" method = "post">
  <p>編集したい番号を入力してください:
    <select name= "editNo">  
      <option value="未選択">選択してください</option>
      <?php 
      $sql = 'SELECT * FROM posts';
      $stmt = $dbh->query($sql);
      $stmt-> execute();
      $cnt = $stmt->rowCount();
      echo $cnt;
        for ($i = 1; $i <= $cnt; $i++) {
          echo "<option value = '{$i}'>{$i}</option>";
        }
        if(empty($cnt)) {
          echo "<option value = '{$i}'> ' ' </option>";
        }
      ?>
    </select>
  </p>
  <p>パスワードを入力してください:
    <input type = "password" name = "edit_pass">
  </p>
  <input type = "submit" name = "edit" value = "編集">
  </form>
  <p>-------------------------------------------------------------------------------</p>
  <!-- 削除フォーム -->
  <form action = "" method = "post" onSubmit="return check()">
  <p>削除したい番号を入力してください:
    <select name= "deleteNo">  
      <option value="未選択">選択してください</option>
      <?php 
      $sql = 'SELECT * FROM posts';
      $stmt = $dbh->query($sql);
      $stmt-> execute();
      $cnt = $stmt->rowCount();
      echo $cnt;
        for ($i = 1; $i <= $cnt; $i++) {
          echo "<option value = '{$i}'>{$i}</option>";
        }
        if(empty($cnt)) {
          echo "<option value = '{$i}'> ' ' </option>";
        }
      ?>
    </select>
  </p>
  <p>パスワードを入力してください:
    <input type = "password" name = "delete_pass">
  </p>
  <!-- 削除確認ダイアログ -->
  <script type="text/javascript">
    function check(){
      if(window.confirm('本当に削除しますか?')){
       return true;
     }else{
       window.alert('キャンセルされました');
       return false;
     }
   }
  </script>
  <input type = "submit" name = "delete" value = "削除" >
  </form>
  <p>-------------------------------------------------------------------------------</p>
  <!-- 投稿一覧表示 -->
  <h2>投稿一覧(
    <?php
      $sql = 'SELECT * FROM posts';
      $stmt = $dbh->query($sql);
      $stmt-> execute();
      $cnt = $stmt->rowCount();
      echo $cnt;
    ?>
    件)</h2>
  <?php
   $sql = 'SELECT * FROM posts';
   $stmt = $dbh->query($sql);
   $stmt-> execute();
     $res = $dbh-> query('SELECT * FROM posts');
       foreach($res as $value) {
         echo $value['id']."\t";
         echo $value['name']."\t";
         echo $value['comment']."\t";
         echo $value['postDate'];
         echo "<br>";
         echo "<p>---------------------------------------------------------------</p>";
       }
  
  ?>
  <p>-------------------------------------------------------------------------------</p>
</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>課題2-応用</title>
</head>
<body>
<?php
// データベース接続
$dsn = 'mysql:dbname=*********;host=localhost';
$user = '**********';
$password = '********';
try {

  $dbh = new PDO($dsn, $user, $password, [PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION] );

  //データベースに接続できなかった時
  } catch (PDOException $e) {

    echo "接続失敗: " . $e->getMessage() . "\n";
    exit();
  }

    //テーブル作成
    $stmt = $dbh->query("CREATE TABLE IF NOT EXISTS posts2 (
      id INT AUTO_INCREMENT PRIMARY KEY,
      name TEXT,
      comment TEXT,
      postDate TEXT,
      new_pass TEXT
      )"
    );

    // 新規投稿
    // if($_SERVER["REQUEST_METHOD"] === 'POST') {
      if(isset($_POST["send"]) && isset($_POST["name"]) && isset($_POST["comment"]) && isset($_POST["new_pass"]) && empty($_POST["hidden_editNo"])) {
        if(!empty($_POST["comment"]) && !empty($_POST["new_pass"]) && isset($_POST["send"])) {
          $name = trim($_POST["name"]);
          $comment = trim($_POST["comment"]);
          $send = $_POST["send"];
          $new_pass = trim($_POST["new_pass"]);
          $postDate = date('Y-m-d H:i:s');
          if(empty($name)) { 
            $name = "名無し";
          }
          $stmt = $dbh->prepare("INSERT INTO posts2 (name,comment,postDate,new_pass) VALUES (:name,:comment,:postDate,:new_pass)");
          $params = array(':name'=>$name,':comment'=>$comment,':postDate'=> $postDate,':new_pass'=> $new_pass);
          $stmt->execute($params);
        } elseif(empty($_POST["comment"]) && !empty($_POST["new_pass"]) && isset($_POST["send"])) {
          echo "<script>alert('コメントが入力されていません。');</script>";
        } elseif(empty($_POST["new_pass"]) && !empty($_POST["comment"]) && isset($_POST["send"])) {
          echo "<script>alert('パスワードが入力されていません。');</script>";
        }elseif(isset($_POST["send"]) && empty($_POST["comment"]) && empty($_POST["new_pass"])) {
          echo "<script>alert('パスワードとコメントが入力されていません。');</script>";
        }
      }
    // }

// 編集
// if($_SERVER["REQUEST_METHOD"] === 'POST') {
  if(isset($_POST["edit"]) && isset($_POST["editNo"]) && isset($_POST["edit_pass"])) {
    if(!empty($_POST["editNo"]) && !empty($_POST["edit_pass"])) {
      $edit = $_POST["edit"];
      $editNo = $_POST["editNo"];
      $edit_pass = $_POST["edit_pass"];
      $res = $dbh->query('SELECT * FROM posts2');
      foreach( $res as $value ){
        if($editNo == $value['id'] && $edit_pass == $value['new_pass']) {
          $hidden_editNo = $value['id'];
          $edit_name = $value['name'];
          $edit_comment = $value['comment'];
          $edit_ID = $value['new_pass'];

        } elseif ($editNo == $value['id'] && $edit_pass != $value['new_pass']) {
          echo "<script>alert('パスワードが間違っています。');</script>";
        }
      break;
    }
   } elseif (empty($_POST["editNo"]) && isset($_POST["edit"]) && !empty($_POST["edit_pass"])) {
        echo "<script>alert('番号を入力してください。');</script>";
   } elseif (empty($_POST["edit_pass"]) && isset($_POST["edit"]) && !empty($_POST["editNo"])) {
        echo "<script>alert('パスワードを入力してください。');</script>";
   }
  } 
// }

//編集する値がフォームに表示された後の投稿
if(!empty($_POST["name"]) && !empty($_POST["comment"]) && !empty($_POST["hidden_editNo"])) {
  $name = $_POST["name"];
  $comment = $_POST["comment"];
  $hidden_editNo = $_POST["hidden_editNo"];
  $postDate = date('Y-m-d H:i:s');
  $new_pass = $_POST["new_pass"];
  $res = $dbh->query('SELECT * FROM posts2');
  $stmt = $dbh->prepare("UPDATE posts2 SET name = :name,comment = :comment,postDate =:postDate, new_pass = :new_pass WHERE id = $hidden_editNo");
  $params = array(':name' => $name,':comment'=>$comment,':postDate'=>$postDate,':new_pass'=>$new_pass);
  $stmt->execute($params);
}

// 削除
// if($_SERVER["REQUEST_METHOD"] === 'POST') {
  if(isset($_POST["delete"]) && isset($_POST["deleteNo"]) && isset($_POST["delete_pass"])) {
    if(!empty($_POST["deleteNo"]) && !empty($_POST["delete_pass"])) {
      $delete = $_POST["delete"];
      $deleteNo = $_POST["deleteNo"];
      $delete_pass = $_POST["delete_pass"];
      $res = $dbh->query('SELECT * FROM posts2');
      foreach( $res as $value ){
        if($deleteNo == $value['id'] && $delete_pass == $value['new_pass']) {
          $stmt = $dbh->prepare("DELETE FROM posts2 WHERE id =:id");
          $params = array(':id'=> $deleteNo);
          $stmt->execute($params);
          $sql = "ALTER TABLE posts2 DROP column id";
          $stmt = $dbh->query($sql);
          $sql = "ALTER TABLE posts2 add id int(11) primary key not null auto_increment first";
          $stmt = $dbh->query($sql);
          $sql = "ALTER TABLE posts2 AUTO_INCREMENT = 1"; 
          $stmt = $dbh->query($sql);
        } else if($deleteNo == $value['id'] && $delete_pass != $value['new_pass']) {
            echo "<script>alert('パスワードが間違っています。');</script>";
        }
       break;
      }
    } elseif(empty($_POST["deleteNo"]) && isset($_POST["delete"]) && !empty($_POST["delete_pass"])) {
        echo "<script>alert('番号を入力してください。');</script>";
    } elseif(empty($_POST["delete_pass"]) && isset($_POST["delete"]) && !empty($_POST["deleteNo"])) {
        echo "<script>alert('パスワードを入力してください。');</script>";
    }
  }
// }
?>

<!-- html記述 -->
  <h1>簡易掲示板</h1>
  <p>-------------------------------------------------------------------------------</p>
  <!-- 投稿フォーム -->
  <form action = "" method = "post">
  <!-- 編集モード用 のinput-->
  <input type = "hidden" name = "hidden_editNo" value = "<?php if(isset($hidden_editNo)) {echo $hidden_editNo;}?>">
  <p>名前:
    <input type = "text" name = "name" value = "<?php if(isset($edit_name)) {echo $edit_name;}?>">
  </p>
  <p>コメント:
    <textarea name = "comment"><?php if(isset($edit_comment)) {echo $edit_comment;}?></textarea>
  </p>
  <p>パスワードを入力してください:
    <input type = "password" name = "new_pass" value="<?php if(isset($edit_ID)) {echo $edit_ID;}?>">
  </p>
  <input type = "submit" name = "send" value = "投稿">
  </form>
  <p>-------------------------------------------------------------------------------</p>
  <!-- 編集フォーム -->
  <form action = "" method = "post">
  <p>編集したい番号を入力してください:
    <input type = "text" name = "editNo">
  </p>
  <p>パスワードを入力してください:
    <input type = "password" name = "edit_pass">
  </p>
  <input type = "submit" name = "edit" value = "編集">
  </form>
  <p>-------------------------------------------------------------------------------</p>
  <!-- 削除フォーム -->
  <form action = "" method = "post" onSubmit="return check()">
  <p>削除したい番号を入力してください:
    <input type = "text" name = "deleteNo">
  </p>
  <p>パスワードを入力してください:
    <input type = "password" name = "delete_pass">
  </p>
  <!-- 削除確認ダイアログ -->
  <script type="text/javascript">
    function check(){
      if(window.confirm('本当に削除しますか?')){
       return true;
     }else{
       window.alert('キャンセルされました');
       return false;
     }
   }
  </script>
  <input type = "submit" name = "delete" value = "削除" >
  </form>
  <p>-------------------------------------------------------------------------------</p>
  <!-- 投稿一覧表示 -->
  <h2>投稿一覧(
    <?php
      $sql = 'SELECT * FROM posts2';
      $stmt = $dbh->query($sql);
      $stmt-> execute();
      $cnt = $stmt->rowCount();
      echo $cnt;
    ?>
    件)</h2>
  <?php
   $sql = 'SELECT * FROM posts2';
   $stmt = $dbh->query($sql);
   $stmt-> execute();
     $res = $dbh-> query('SELECT * FROM posts2');
       foreach($res as $value) {
         echo $value['id']."\t";
         echo $value['name']."\t";
         echo $value['comment']."\t";
         echo $value['postDate'];
         var_dump($value['new_pass']);
         echo "<br>";
         echo "<p>---------------------------------------------------------------</p>";
       }
  
  ?>
  <p>-------------------------------------------------------------------------------</p>
</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
</head>
<body>
<h3>本当にこの投稿を削除しますか?</h3><hr>

<?php
	$dsn = 'データベース名';
	$user = 'ユーザー名';
	$password = 'パスワード';
	
	try {
		$dbh = new PDO($dsn, $user, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
	} catch (PDOException $e) {
		echo $e->getMessage();
		die();
	}
		
	$table = 'SELECT * FROM post_list';
	$get = $dbh ->query($table);
	$posts = $get ->fetchAll();
	
	if (!empty($_POST['delete']) and !empty($_POST['delete_pass'])) {
		foreach ($posts as $post) {
			if ($_POST['delete'] == $post['id'] and $_POST['delete_pass'] == $post['password']) {
				$id = $post['id'];
				$name = $post['name'];
				$comment = $post['comment'];
				$time = $post['time'];
				$pass = $post['password'];
				echo $post['id']. " ". $post['name']. "<br>". $post['comment']. "<br>". $post['time']. "<hr>";
			}
		}
	}
	
	if (empty($id)) {
		echo "パスワードが違います";
	}	
	$dbh = null;
?>
<form action="kadai_2-6-db_home.php" method="post">
	<input type="hidden" name="delete" value="<?php if (!empty($id)) { echo $id; } ?>">
	<input type="hidden" name="delete_pass" value="<?php if (!empty($pass)) { echo $pass; } ?>">
	<input type="submit" value="削除">
</form>
</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<HTML>
<head>
<meta charset="UTF-8">
<title>kadai_2</title>
</head>
<body>

  <script type="text/javascript">
   function check(){
     if(window.confirm('本当に削除しますか?')){
       return true;
     }else{
       window.alert('キャンセルされました');
       return false;
     }
   }
 </script>

  <?php
  if(isset($_POST["name"]) && isset($_POST["comment"]) && isset($_POST["pass"]) && empty($_POST["num"])){
    if(!empty($_POST["name"]) && !empty($_POST["comment"])){
      $name=$_POST["name"];
      $comment=$_POST["comment"];
        $datefile="kadai_2-6.txt";
        $date=date("Y-m-d");
        $fp=fopen($datefile,"a");
        $num=count(file($datefile));
        $num++;
        $pass=$_POST["pass"];
        $newdate=$num."<>".$name."<>".$comment."<>".$date."<>".$pass."<>"."\n";
        fwrite($fp,$newdate);
        fclose($fp);
        }
      else{
        echo "未入力です。";
      }
    }






    $datefile="kadai_2-6.txt";
    if(isset($_POST["delete"]) && isset($_POST["delete_pass"])){
    if (!empty($_POST["delete"]) && !empty($_POST["delete_pass"])) {
      $delete = $_POST["delete"];
      $delete_pass=$_POST["delete_pass"];
      $delCon =file($datefile);
      $fp = fopen($datefile, "w");
      for ($j = 0; $j < count($delCon); $j++) {
        $delDate = explode("<>", $delCon[$j]);
        if ($delDate[0]== $delete && $delDate[4]==$delete_pass) {
          echo "削除しました。";
          for ($j = 0; $j < count($delCon); $j++) {
            $delDate = explode("<>", $delCon[$j]);
            if($delDate[0]> $delete){
              $delDate[0]=$delDate[0]-1;
            fwrite($fp,$delDate[0]."<>".$delDate[1]."<>".$delDate[2]."<>".$delDate[3]."<>".$delDate[4]."<>"."\n");
            }
          }
          break;
        }
        else if($delDate[0]== $delete && $delDate[4]!=$delete_pass){
          echo "パスワードが間違っています。";
          fwrite($fp,$delCon[$j]);
        }
        else{
          fwrite($fp,$delCon[$j]);
        }
      }
      fclose($fp);
    }
    else if(empty($_POST["delete"]) && !empty($_POST["delete_pass"])){
      echo "削除対象番号を入力してください。";
    }
    else if(!empty($_POST["delete"]) && empty($_POST["delete_pass"])){
      echo "パスワードを入力してください。";
    }
    else{
      echo "未入力です。";
    }
  }




  $datefile="kadai_2-6.txt";
  if(isset($_POST["edit"]) && isset($_POST["edit_pass"])){
    if (!empty($_POST["edit"]) && !empty($_POST["edit_pass"])) {
    $edit=$_POST["edit"];
    $edit_pass=$_POST["edit_pass"];
    $editCon=file($datefile);
    for($i=0;$i<count($editCon);$i++) {
      $editDate=explode("<>",$editCon[$i]);
      if ($edit==$editDate[0] && $edit_pass==$editDate[4]){
      $edit_num=$editDate[0];
      $edit_name=$editDate[1];
      $edit_comment=$editDate[2];
      $edit_ID=$editDate[4];
      break;
            }
      else if($edit==$editDate[0] && $edit_pass!=$editDate[4]){
        echo "パスワードが間違っています。";
      }
          }
        }
        else if(empty($_POST["edit"]) && !empty($_POST["edit_pass"])){
          echo "編集対象番号を入力してください。";
        }
        else if(!empty($_POST["edit"]) && empty($_POST["edit_pass"])){
          echo "パスワードを入力してください。";
        }
        else{
          echo "未入力です。";
        }
       }

       if(!empty($_POST["name"]) && !empty($_POST["comment"]) && !empty($_POST["num"])){
         $name=$_POST["name"];
         $comment=$_POST["comment"];
         $num=$_POST["num"];
         $date=date("Y-m-d");
         $pass=$_POST["pass"];
         $editCon=file($datefile);
         $fp=fopen($datefile,"w");
         for($i=0;$i<count($editCon);$i++) {
           $editDate=explode("<>",$editCon[$i]);
           if ($editDate[0]==$num) {
             fwrite($fp,$num."<>".$name."<>".$comment."<>".$date."<>".$pass."<>"."\n");
           }
          else{
            fwrite($fp,$editCon[$i]);
          }
        }
        fclose($fp);
      }

  ?>



<h1>簡易掲示板</h1>
<p>ーーーーーーーーーーーーーー</p>
  <form action="kadai_2-6.php" method="post">
    <input type="hidden" name="num" value="<?php if(isset($edit_num)){echo $edit_num;}?>">
    <p>・名前</p>
      <input type="text" name="name" value="<?php if(isset($edit_name)){echo $edit_name;}?>">
      <p>・コメント</p>
    <textarea name="comment"><?php if(isset($edit_comment)){echo $edit_comment;}?></textarea>
      <p>pw:</p>
    <input type="text" name="pass" value="<?php if(isset($edit_ID)){echo $edit_ID;}?>">
      <br>
      <input type="submit"  value="投稿">
      </br>
  </form>
<p>ーーーーーーーーーーーーーー</p>
  <form action="kadai_2-6.php" method="post" onSubmit="return check()">
      <p>・削除対象番号</p>
      <input type="text" name="delete">
      <br>
      pw:<input type="text" name="delete_pass">
      </br>
      <input type="submit" value="削除">

  </form>
<p>ーーーーーーーーーーーーーー</p>
  <form action="kadai_2-6.php" method="post">
    <p>・編集対象番号</p>
    <input type="text" name="edit">
    <br>
    pw:<input type="text" name="edit_pass">
    </br>
    <input type="submit" value="編集">

  </form>

  <p>ーーーーー投稿一覧ーーーーー</p>

  <?php

    $datefile="kadai_2-6.txt";
    if(file_exists($datefile)){
    $line = file($datefile);
    foreach($line as $value){
      $array = explode("<>",$value);
      echo "$array[0] . $array[1] . $array[2] . $array[3]";
      echo "<br>";
    }
  }


  ?>

</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
</head>
<body>
	<?php
		$now = date('Y/m/d H:i:s');
		$dsn = 'データベース名';
		$user = 'ユーザー名';
		$password = 'パスワード';
		
		try {
			$dbh = new PDO($dsn, $user, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
			
			$sql = 'CREATE TABLE IF NOT EXISTS post_list (
				id INT PRIMARY KEY,
				name VARCHAR(20),
				comment TEXT,
				time DATETIME,
				password CHAR(20)
			)';
			
			$res = $dbh->query($sql);
		} catch (PDOException $e) {
			echo $e->getMessage();
			die();
		}
		
		$table = 'SELECT * FROM post_list';
		$get = $dbh ->query($table);
		$posts = $get ->fetchAll();
		$num = count($posts) + 1 ;
		
		if (!empty($_POST['name']) and !empty($_POST['comment']) and !empty($_POST['pass'])){
			$insert = 'INSERT INTO post_list (
				id, name, comment, time, password
			) VALUE (
				:id, :name, :comment, :time, :password
			)';
			
			$post = $dbh->prepare($insert);
			$new_post = $post->execute(array(
				':id' => $num,
				':name' => $_POST['name'],
				':comment' => $_POST['comment'],
				':time' => $now,
				':password' => $_POST['pass']
			));	
		}
		
		if (!empty($_POST['delete']) and !empty($_POST['delete_pass'])) {
			foreach ($posts as $post) {
				if ($_POST['delete'] == $post['id'] and $_POST['delete_pass'] == $post['password']) {
					$id = $post['id'];
					$delete = 'DELETE FROM post_list WHERE id=:id';
					$stmt = $dbh->prepare($delete);
					$result = $stmt->execute(array(':id' => $id));
				} elseif ($post['id'] > $_POST['delete']) {
					$id = $post['id'] - 1;
					$sql = 'UPDATE post_list SET id=:id WHERE id=:num';
					$stmt = $dbh->prepare($sql);
					$result = $stmt->execute(array(
						':id' => $id,
						':num' => $post['id']
					));
				}
			}
		}
				
		if (!empty($_POST['edit-num']) and !empty($_POST['edit-name']) and !empty($_POST['edit-comment']) and !empty($_POST['edit-pass'])) {
			foreach ($posts as $post) {
				if ($_POST['edit-num'] == $post['id'] and $_POST['edit-pass'] == $post['password']) {
					$id = $post['id'];
					$name = $_POST['edit-name'];
					$comment = $_POST['edit-comment'];
					$update = 'UPDATE post_list SET name=:name, comment=:comment, time=:time WHERE id=:id';
					$stmt = $dbh->prepare($update);
					$res = $stmt->execute(array(
						':name' => $name,
						':comment' => $comment,
						':time' => $now,
						':id' => $id
					));
				}
			}
		}	
		
		$dbh = null;
	?>

	<h3>投稿一覧<h3>
	<form action="kadai_2-6-db_post.php" method="post">
		<input type="submit" value="新規投稿">
	</form>
	<form action="kadai_2-6-db_delete.php" method="post">
		<input type="submit" value="削除">
	</form>
	<form action="kadai_2-6-db_edit.php" method="post">
		<input type="submit" value="編集">
	</form>
	<hr>
	
	<?php
		try {
			$dbh = new PDO($dsn, $user, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
		} catch (PDOException $e) {
			echo $e->getMessage();
			die();
		}
		
		$table = 'SELECT * FROM post_list';
		$get = $dbh ->query($table);
		$posts = $get ->fetchAll();
		foreach($posts as $post) {
			echo $post['id']. " ". $post['name']. "<br>". $post['comment']. "<br>". $post['time']. "<hr>";
		}
		$dbh = null;
	?>

</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>MySQL</title>
</head>
<body>
  <?php

    $dsn = 'mysql:dbname=**********;host=localhost';
    $user = '**************';
    $password = '********';

    try{
        $dbh = new PDO($dsn, $user, $password,
        [
          PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION
        ]
      );

      echo "接続に成功<br>";

      //テーブルの作成
      $stmt = $dbh->query("CREATE TABLE test (id INT,name TEXT)");
      
      //テーブル一覧表示
      echo "テーブル一覧表示<br>";
      $stmt = $dbh->query('SHOW TABLES');
      while($re = $stmt->fetch(PDO::FETCH_ASSOC)){
        var_dump($re);
        echo "<br>";
      }
      echo "<br>";
      //テーブルの中身確認
      echo "テーブルの中身確認<br>";
      $stmt = $dbh->query("SHOW COLUMNS FROM test");
      while($re = $stmt->fetchall(PDO::FETCH_COLUMN)){
        var_dump($re);
        echo "<br>";
      }
      echo "<br>";
      
      //データ入力
      $stmt = $dbh->query("INSERT INTO test VALUE (2,'田中'),(3, '鈴木')");
      $result = $stmt->fetchall();
      echo "<br>";
      
      //データ表示
      echo "データ表示<br>";
      $result_data = $dbh->query("SELECT * FROM test");
      foreach($result_data as $row) {
        echo "id:{$row['id']}<br>";
        echo "名前:{$row['name']}<br>";
      
    }
    echo "<br>";
    
    // データ編集
    $sql = 'UPDATE test SET name = "佐藤" where id = 2'; 
    $stmt = $dbh->prepare($sql);
    $stmt->execute();
 
    //データ編集後の表示
    echo "データ編集<br>";
    $update_data = $dbh->query("SELECT * FROM test");
      foreach($update_data as $row) {
        echo "id:{$row['id']}<br>";
        echo "名前:{$row['name']}<br>";
    }
    echo "<br>";

    // データ削除
    $sql = 'DELETE FROM test WHERE id = 2';
    $stmt = $dbh->prepare($sql);
    $stmt->execute();
    
    //データ削除後の表示
    echo "データ削除<br>";
    $delete_data = $dbh->query("SELECT * FROM test");
    foreach($delete_data as $row) {
      echo "id:{$row['id']}<br>";
      echo "名前:{$row['name']}<br>";
  }

    } catch (PDOException $e) {
      echo "接続失敗" . $e->getMessage();
      exit();
    }
    $dbh = null;
    
    ?>
</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
</head>
<body>
<h3>内容を編集してください</h3><hr>
<?php
	$dsn = 'データベース名';
	$user = 'ユーザー名';
	$password = 'パスワード';
	
	try {
		$dbh = new PDO($dsn, $user, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
	} catch (PDOException $e) {
		echo $e->getMessage();
		die();
	}
	
	$table = 'SELECT * FROM post_list';
	$get = $dbh ->query($table);
	$posts = $get ->fetchAll();
	
	if (!empty($_POST['edit']) and !empty($_POST['edit_pass'])) {
		foreach ($posts as $post) {
			if ($_POST['edit'] == $post['id'] and $_POST['edit_pass'] == $post['password']) {
				$id = $post['id'];
				$name = $post['name'];
				$comment = $post['comment'];
				$time = $post['time'];
			}
		}
	}
	
	if (empty($id)) {
		echo "パスワードが違います";
	}	
	$dbh = null;
?>
<form action="kadai_2-6-db_edit-confirm.php" method="post">
	<input type="hidden" name="number" value="<?php if (!empty($id)) {echo $id;} ?>">
	<input type="text" name="name" value="<?php if (!empty($name)) {echo $name;} ?>"><br>
	<input type="text" name="comment" value="<?php if (!empty($comment)) {echo $comment;} ?>"><br>
	<input type="hidden" name="pass" value="<?php if (!empty($_POST['edit_pass'])) {echo $_POST['edit_pass'];} ?>"><br>
	<input type="submit" value="確認">
</form>
</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
</head>
<body>
<h3>本当にこの投稿を削除しますか?</h3><hr>

<?php
	$dsn = 'データベース名';
	$user = 'ユーザー名';
	$password = 'パスワード';
	
	try {
		$dbh = new PDO($dsn, $user, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
	} catch (PDOException $e) {
		echo $e->getMessage();
		die();
	}
		
	$table = 'SELECT * FROM post_list';
	$get = $dbh ->query($table);
	$posts = $get ->fetchAll();
	
	if (!empty($_POST['delete']) and !empty($_POST['delete_pass'])) {
		foreach ($posts as $post) {
			if ($_POST['delete'] == $post['id'] and $_POST['delete_pass'] == $post['password']) {
				$id = $post['id'];
				$name = $post['name'];
				$comment = $post['comment'];
				$time = $post['time'];
				echo $post['id']. " ". $post['name']. "<br>". $post['comment']. "<br>". $post['time']. "<hr>";
			}
		}
	}
	
	if (empty($id)) {
		echo "パスワードが違います";
	}	
	$dbh = null;
?>
<form action="kadai_2-6-db_home.php" method="post">
	<input type="hidden" name="delete" value="<?php if (!empty($_POST['delete'])) { echo $_POST['delete']; } ?>">
	<input type="hidden" name="delete_pass" value="<?php if (!empty($_POST['delete_pass'])) { echo $_POST['delete_pass']; } ?>">
	<input type="submit" value="削除">
</form>
</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
</head>
<body>
	<?php
		$now = date('Y/m/d H:i:s');
		$dsn = 'データベース名';
		$user = 'ユーザー名';
		$password = 'パスワード';
		
		try {
			$dbh = new PDO($dsn, $user, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
			
			$sql = 'CREATE TABLE IF NOT EXISTS post_list (
				id INT AUTO_INCREMENT PRIMARY KEY,
				name VARCHAR(20),
				comment TEXT,
				time DATETIME,
				password CHAR(20)
			)';
			
			$res = $dbh->query($sql);
		} catch (PDOException $e) {
			echo $e->getMessage();
			die();
		}
		
		$table = 'SELECT * FROM post_list';
		$get = $dbh ->query($table);
		$posts = $get ->fetchAll();
		
		if (!empty($_POST['name']) and !empty($_POST['comment']) and !empty($_POST['pass'])){
			$insert = 'INSERT INTO post_list (
				name, comment, time, password
			) VALUE (
				:name, :comment, :time, :password
			)';
			
			$post = $dbh->prepare($insert);
			$new_post = $post->execute(array(
				':name' => $_POST['name'],
				':comment' => $_POST['comment'],
				':time' => $now,
				':password' => $_POST['pass']
			));	
		}
		
		if (!empty($_POST['delete']) and !empty($_POST['delete_pass'])) {
			foreach ($posts as $post) {
				if ($_POST['delete'] == $post['id'] and $_POST['delete_pass'] == $post['password']) {
					$id = $post['id'];
					$delete = 'DELETE FROM post_list WHERE id=:id';
					$stmt = $dbh->prepare($delete);
					$result = $stmt->execute(array(':id' => $id));
				}
			}
		}
		
		if (!empty($_POST['edit-num']) and !empty($_POST['edit-name']) and !empty($_POST['edit-comment']) and !empty($_POST['edit-pass'])) {
			foreach ($posts as $post) {
				if ($_POST['edit-num'] == $post['id'] and $_POST['edit-pass'] == $post['password']) {
					$id = $post['id'];
					$name = $_POST['edit-name'];
					$comment = $_POST['edit-comment'];
					$update = 'UPDATE post_list SET name=:name, comment=:comment, time=:time WHERE id=:id';
					$stmt = $dbh->prepare($update);
					$res = $stmt->execute(array(
						'name' => $name,
						'comment' => $comment,
						'time' => $now,
						'id' => $id
					));
				}
			}
		}	
		
		$dbh = null;
	?>

	<h3>投稿一覧<h3>
	<form action="kadai_2-6-db_post.php" method="post">
		<input type="submit" value="新規投稿">
	</form>
	<form action="kadai_2-6-db_delete.php" method="post">
		<input type="submit" value="削除">
	</form>
	<form action="kadai_2-6-db_edit.php" method="post">
		<input type="submit" value="編集">
	</form>
	<hr>
	
	<?php
		try {
			$dbh = new PDO($dsn, $user, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
		} catch (PDOException $e) {
			echo $e->getMessage();
			die();
		}
		
		$table = 'SELECT * FROM post_list';
		$get = $dbh ->query($table);
		$posts = $get ->fetchAll();
		foreach($posts as $post) {
			echo $post['id']. " ". $post['name']. "<br>". $post['comment']. "<br>". $post['time']. "<hr>";
		}
		$dbh = null;
	?>

</body>
</html>
Don't you submit code?
Submit