anonymous No title
PHP
<?php
session_start();
$_SESSION = array();
session_destroy();
?>

<!DOCTYPE html>
<html>
<head>
<title>ログアウト</title>
</head>
<body>
<h1>
<font size='5'>ログアウトしました</font>
</h1>
<p><a href='http://co-19-271.99sv-coco.com/kadai3_2_login.php'>ログインページに戻る</a></p>
</body>
</html>
anonymous No title
PHP
<?php
if(isset($_POST['login'])){
    if(strlen($_POST['user_id']) && strlen($_POST['password'])){
        session_start();
        $user_id = $_POST['user_id'];
        $password = $_POST['password'];
        $pdo = new PDO('mysql:host=localhost;dbname=co_19_271_99sv_coco_com', 'co-19-271.99sv-c', 'Xc5tnWDA');
        $stmt = $pdo->prepare('SELECT * FROM kadai3_1_users WHERE id = :id');
        $stmt->bindValue(':id', $user_id);
        $stmt->execute();
        $member = $stmt->fetch();
        if(strcmp($member['password'], $password) == 0){
            $_SESSION['user_id'] = $user_id;
            $_SESSION['name'] = $member['name'];
            $_SESSION['password'] = $password;
            header("Location: http://co-19-271.99sv-coco.com/kadai3_2_top.php");
        }else{
            echo 'IDかパスワードが間違っています<br/>';
        }
    }else{
        echo "未入力の欄があります<br/>";
    }
}

?>

<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ログイン</title>
</head>
<body>
    <h1>ログイン</h1>
    <form action="kadai3_2_login.php" method="post">
    <p>ID</p>
    <input type = "text" name ="user_id"><br/>
    <p>パスワード</p>
    <input type = "text" name ="password"><br/>
    <input type = "submit" name="login" value ="送信"><br/>
    </form>
    <a href="http://co-19-271.99sv-coco.com/kadai3_2_signup.php">新規登録</a>
</body>
</html>
anonymous No title
PHP
<?php
session_start();
$pdo = new PDO('mysql:host=localhost;dbname=co_19_271_99sv_coco_com', 'co-19-271.99sv-c', 'Xc5tnWDA');
$pdo->query('CREATE TABLE IF NOT EXISTS post_table_apply (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(20),
    comment TEXT,
    date DATE,
    password VARCHAR(20)
    )');
if(!isset($_SESSION['user_id'])){
    header("Location: http://co-19-271.99sv-coco.com/kadai3_2_login.php");
    exit;
}else{
    echo 'ログイン済み<br/>';
    echo "あなたのID: ".$_SESSION['user_id']."<br/>";
    $name = $_SESSION['name'];
    echo "あなたの名前: ".$name."<br/><br/>";
}

if(isset($_POST['edit']) && isset($_POST['password'])){
    if(strlen($_POST['edit']) && strlen($_POST['password'])){
        $password = $_POST['password'];
        $stmt = $pdo->prepare('SELECT * FROM post_table_apply WHERE id = :id');
        $stmt->execute(array(':id' => $_POST['edit']));
        $edit_post = $stmt->fetch(PDO::FETCH_ASSOC);
        if($edit_post['password'] == $password){
            $edit_id = $_POST['edit'];
            $edit_name = $edit_post['name'];
            $edit_txt = $edit_post['comment'];
        }else{
            echo "編集パスワードが間違っています<br/>";
        }
    }else{
        echo "編集番号かパスワードが空欄になっています<br/>";
    }
}

if(isset($_POST['delete']) && isset($_POST['password'])){
    if(strlen($_POST['delete']) && strlen($_POST['password'])){
        $delete_id = $_POST['delete'];
        $password = $_POST['password'];
        $stmt = $pdo->prepare('SELECT * FROM post_table_apply WHERE id = :id');
        $stmt->execute(array(':id' => $delete_id));
        $delete_post = $stmt->fetch(PDO::FETCH_ASSOC);
        if($delete_post['password'] == $password){
            $stmt = $pdo->prepare('DELETE FROM post_table_apply WHERE id=:id');
            $stmt->execute(array(':id' => $delete_id));
            echo $delete_id."番の投稿を削除しました<br/>";
        }else{
            echo "削除パスワードが間違っています<br/>";
        }
    }else{
        echo "削除番号かパスワードが空欄になっています<br/>";
    }
}

if(isset($_POST['comment']) && isset($_POST['name']) && isset($_POST['password'])){
    if(strlen($_POST['comment']) && strlen($_POST['name']) && strlen($_POST['password'])){
        $comment = $_POST['comment'];
        $name = $_POST['name'];
        $password = $_POST['password'];
        $date = date("Y-m-d");
        $stmt = $pdo->prepare('INSERT INTO post_table_apply (name, comment, date, password) VALUES (:name, :comment, :date, :password)');
        $flag = $stmt->execute(array(':name' => $name, ':comment' => $comment, ':date' => $date, ':password' => $password));
        if ($flag){
            print('投稿しました<br>');
        }else{
            print('投稿に失敗しました<br>');
        }
    }else{
        echo "未入力の欄があります<br/>";
    }
}elseif(isset($_POST['comment']) && isset($_POST['name']) && isset($_POST['edit_id'])){
    if(strlen($_POST['comment']) && strlen($_POST['name']) && strlen($_POST['edit_id'])){
        $comment = $_POST['comment'];
        $name = $_POST['name'];
        $date = date("Y-m-d");
        $edit_id = $_POST['edit_id'];
        $stmt = $pdo->prepare("UPDATE post_table_apply SET name = :name, comment = :comment, date = :date WHERE id = :id");
        $stmt->execute(array(':name' => $name, ':comment' => $comment, ':date' => $date, ':id' => $edit_id));
        $edit_id = -10000;
    }else{
        echo "未入力の欄があります<br/>";
    }
}

echo "投稿一覧<br/>";
$result_rows = $pdo->query('SELECT * FROM post_table_apply');
foreach ( $result_rows as $row ) {
    echo "{$row['id']}";
    echo " {$row['name']}";
    echo " {$row['comment']}";
    echo " {$row['date']}";
    echo "<br/>";
}
echo "<br/>";
?>
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>投稿</title>
</head>
<body>
    <h1>投稿フォーム</h1>
    <form action="kadai3_2_top.php" method="post">
    <p>名前</p>
    <input type = "text" name ="name" value=<?php echo $name; ?> readonly>
    <p>コメント</p>
    <input type = "text" name ="comment" value="<?php if(isset($edit_txt)){echo $edit_txt;} ?>"><br/>
    <?php if(!isset($edit_id) || $edit_id == -10000){
    ?>
        <p>パスワード</p>
        <input type = "text" name ="password"><br/>
    <?php
    }
    ?>
    <input type="hidden" name ="edit_id" value="<?php if(isset($edit_id)){echo $edit_id;} ?>">
    <input type = "submit" value ="送信">
    </form>
    <script>
    function delete_confirm() {
            var select = confirm("削除してよろしいですか?");
            return select;
    }
    </script>
    <h1>削除</h1>
    <p>削除する投稿の番号</p>
    <form action="kadai3_2_top.php" method="post" onsubmit="return delete_confirm()">
    <input type = "text" name ="delete"><br/>
    <p>パスワード</p>
    <input type = "text" name ="password"><br/>
    <input type = "submit" value ="送信">
    </form>
    <h1>編集</h1>
    <p>編集する投稿の番号</p>
    <form action="kadai3_2_top.php" method="post">
    <input type = "text" name ="edit"><br/>
    <p>パスワード</p>
    <input type = "text" name ="password"><br/>
    <input type = "submit" value ="送信"><br/>
    <a href="http://co-19-271.99sv-coco.com/kadai3_2_signup.php">新規登録</a>
    </form>
</body>
</html>
anonymous No title
PHP
<?php
$pdo = new PDO('mysql:host=localhost;dbname=co_19_271_99sv_coco_com', 'co-19-271.99sv-c', 'Xc5tnWDA');
$pdo->query('CREATE TABLE IF NOT EXISTS kadai3_1_users (
    id INT(5) AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(20),
    password VARCHAR(20)
    )');

if(isset($_POST['name']) && isset($_POST['password'])){
    if(strlen($_POST['name']) && strlen($_POST['password'])){
        $name = $_POST['name'];
        $password = $_POST['password'];
        $stmt = $pdo->prepare('INSERT INTO kadai3_1_users (name, password) VALUES (:name, :password)');
        $flag = $stmt->execute(array(':name' => $name, ':password' => $password));
        $user_id = $pdo->lastinsertid();
        if ($flag){
            print('ユーザー登録が完了しました<br>');
            echo 'あなたのユーザー情報<br/>';
            echo "ID: ".$user_id;
            echo "<br/>";
            echo "名前: ".$name;
            echo "<br/>";
            echo "パスワード: ".$password;
            echo "<br/>";
            echo "<br/>";
        }else{
            print('ユーザー登録に失敗しました<br>');
        }
    }else{
        echo '未入力の項目があります<br/>';
    }
}

echo "ユーザー一覧<br/>";
$result_rows = $pdo->query('SELECT * FROM kadai3_1_users');
foreach ( $result_rows as $row ) {
    echo "{$row['id']}";
    echo " {$row['name']}";
    echo "<br/>";
}
echo "<br/>";

?>

<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>新規登録</title>
</head>
<body>
    <h1>新規登録フォーム</h1>
    <form action="kadai3_2_signup.php" method="post">
    <p>名前</p>
    <input type = "text" name ="name"><br/>
    <p>パスワード</p>
    <input type = "text" name ="password"><br/>
    <input type = "submit" value ="送信"><br/>
    </form>
    <a href="http://co-19-271.99sv-coco.com/kadai3_2_top.php">投稿ページ</a>
    <?php
    if(isset($_SESSION['user_id'])){
    ?>
        <a href="http://co-19-271.99sv-coco.com/kadai3_2_login.php">ログイン</a>
    <?php
    }else{
    ?>
        <a href="http://co-19-271.99sv-coco.com/kadai3_2_logout.php">ログアウト</a>
    <?php
    }
    ?>
</body>
</html>
anonymous No title
PHP
<?php
//キャッシュ部分
require_once("Cache/Lite.php");

$cache_opt = array(
  "cacheDir" => "Cache/tmp/", //キャッシュ保存場所
  "lifeTime" => 3600, //保存時間
  "caching" => true,
  "automaticSerialization" => true,
  "automaticCleaningFactor" => 20 //自動キャッシュ削除
);
$cache = new Cache_Lite($cache_opt);

//Smarty部分
require_once("./libs/Smarty.class.php");
$smarty = new Smarty();
$smarty->template_dir = "templates";
$smarty->compile_dir = "templates_c";

session_start();
$session_name = $_SESSION['user_name'];
$cache_id = $_SESSION['user_id'];
$smarty->assign("session_name",$session_name);

//デザインの分別
$ua = $_SERVER['HTTP_USER_AGENT'];
if((strpos($ua, 'Android') !== false) && (strpos($ua, 'Mobile') !== false) || (strpos($ua, 'iPhone') !== false)){
  $design = 10;
}elseif((strpos($ua, 'mobile' !== false))){
  $design = 11;
}elseif((strpos($ua, 'Android') !== false) || (strpos($ua, 'iPad') !== false)){
  $design = 12;
} else {
  $design = 13;
}

//初期値
$blank = 11;
$id[0] = "番号を選択してください";
$rows[0] = array(
  "id"   => 0,
  "name" => "",
  "body" => "投稿がありません",
  "time" => "",
  "file_pass" => "",
  "file_type" => ""
);

//自動サイト更新
$script_name = $_SERVER["SCRIPT_NAME"];

//データベースへの接続
$user = 'root';
$pass = '';

try {
  $db = new PDO('mysql:host=localhost;dbname=test;charaset=utf8;', $user, $pass);
} catch (PDOException $e) {
  echo "データベースに接続できません。".$e->getMessage();
  exit;
}

//テーブル作成
$create_query = <<< _CHAT_
  CREATE TABLE IF NOT EXISTS chatlog3 (
    id       int not null auto_increment primary key,
    name       TEXT NOT NULL,
    body       TEXT NOT NULL,
    pass       TEXT NOT NULL,
    file_pass  TEXT,
    file_type  TEXT,
    ctime      INTEGER
  );
_CHAT_;
$result = $db->exec($create_query);
if($result === false) {
  print_r($db->errorInfo()); 
  exit;
}

 //データの更新
$update = <<< _UPDATE_
  SET @i := 0;
  UPDATE chatlog3 SET id = (@i := @i+1); 
_UPDATE_;

//データを挿入
if(isset($_POST["name"]) && isset($_POST["body"])) {
  if($_POST["name"] == "" || $_POST["body"] == ""){
    $blank = 10;
  }else{
    $template = "INSERT INTO chatlog3 (name, body, pass, ctime)".
                "VALUES(?,?,?,?);";
    $stmt = $db->prepare($template);
  
    $stmt->execute(array($_POST["name"], $_POST["body"], $_POST["pass"], time()));

    $db->exec($update);

    if($data = $cache->get($cache_id)){
      $count = 1;
      $rows = $data;
      foreach($rows as $row){
        $count++;
      }

      $rows[] = array(
        "id"   => $count,
        "name" => $_POST["name"],
        "body" => $_POST["body"],
        "pass" => $_POST["pass"],
        "time" => date("Y/m/d H:i:s", time()),
        "file_pass" => "",
        "file_type" => ""
      );
      
    }

    $cache->save($rows, $cache_id);

    header("location: $script_name"); exit;
  }
}

//未入力かの判定
$smarty->assign("blank", $blank);

//削除・編集番号の取得
$select_query = "SELECT * FROM chatlog3 ORDER BY id ASC";
$stmt = $db->query($select_query);
foreach($stmt as $row){
  $id[] = $row["id"];
}

$smarty->assign("id",$id);

//表示項目の取得
if($data = $cache->get($cache_id)){
  $rows = $data;
  echo "キャッシュ利用中";
} else {
  
  $select_query = "SELECT * FROM chatlog3 ORDER BY id ASC";
  $stmt = $db->query($select_query);

  foreach ($stmt as $row) {
    $id = $row["id"];
    $name = $row["name"];
    $body = $row["body"];
    $pass = $row["pass"];
    $file_pass = $row["file_pass"];//ファイルパス
    $file_type = $row["file_type"];//ファイルのタイプ
    $time = date("Y/m/d H:i:s", $row["ctime"]);
    
    if($id == 1){
      $rows[0] = array(
        "id"   => $id,
        "name" => $name,
        "body" => $body,
        "pass" => $pass,
        "time" => $time,
        "file_pass" => $file_pass,
        "file_type" => $file_type
      );
    } else {
      $rows[] = array(
        "id"   => $id,
        "name" => $name,
        "body" => $body,
        "pass" => $pass,
        "time" => $time,
        "file_pass" => $file_pass,
        "file_type" => $file_type
      );
    } 
  }

  
  $cache->save($rows, $cache_id);
  echo "キャッシュ保存中";
}






$smarty->assign("contents",$rows);

$smarty->assign("design", $design);

$smarty->display("keigiban.html");

?>
anonymous No title
PHP
<?php
$pdo = new PDO('mysql:host=localhost;dbname=co_19_271_99sv_coco_com', 'co-19-271.99sv-c', 'Xc5tnWDA');
$pdo->query('CREATE TABLE IF NOT EXISTS kadai3_1_users (
    id INT(5) AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(20),
    password VARCHAR(20)
    )');

if(isset($_POST['name']) && isset($_POST['password'])){
    if(strlen($_POST['name']) && strlen($_POST['password'])){
        $name = $_POST['name'];
        $password = $_POST['password'];
        $stmt = $pdo->prepare('INSERT INTO kadai3_1_users (name, password) VALUES (:name, :password)');
        $flag = $stmt->execute(array(':name' => $name, ':password' => $password));
        $user_id = $pdo->lastinsertid();
        if ($flag){
            print('ユーザー登録が完了しました<br>');
            echo 'あなたのユーザー情報<br/>';
            echo "ID: ".$user_id;
            echo "<br/>";
            echo "名前: ".$name;
            echo "<br/>";
            echo "パスワード: ".$password;
            echo "<br/>";
            echo "<br/>";
        }else{
            print('ユーザー登録に失敗しました<br>');
        }
    }else{
        echo '未入力の項目があります<br/>';
    }
}

echo "ユーザー一覧<br/>";
$result_rows = $pdo->query('SELECT * FROM kadai3_1_users');
foreach ( $result_rows as $row ) {
    echo "{$row['id']}";
    echo " {$row['name']}";
    echo "<br/>";
}
echo "<br/>";

?>

<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>新規登録フォーム</h1>
    <form action="kadai3_1_signup.php" method="post">
    <p>名前</p>
    <input type = "text" name ="name"><br/>
    <p>パスワード</p>
    <input type = "text" name ="password"><br/>
    <input type = "submit" value ="送信"><br/>
    </form>
    <a href="http://co-19-271.99sv-coco.com/kadai3_1_top.php">投稿ページ</a>
</body>
</html>
anonymous No title
PHP
<?php
$pdo = new PDO('mysql:host=localhost;dbname=co_19_271_99sv_coco_com', 'co-19-271.99sv-c', 'Xc5tnWDA');
$pdo->query('CREATE TABLE IF NOT EXISTS post_table_apply (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(20),
    comment TEXT,
    date DATE,
    password VARCHAR(20)
    )');

if(isset($_POST['edit']) && isset($_POST['password'])){
    if(strlen($_POST['edit']) && strlen($_POST['password'])){
        $password = $_POST['password'];
        $stmt = $pdo->prepare('SELECT * FROM post_table_apply WHERE id = :id');
        $stmt->execute(array(':id' => $_POST['edit']));
        $edit_post = $stmt->fetch(PDO::FETCH_ASSOC);
        if($edit_post['password'] == $password){
            $edit_id = $_POST['edit'];
            $edit_name = $edit_post['name'];
            $edit_txt = $edit_post['comment'];
        }else{
            echo "編集パスワードが間違っています<br/>";
        }
    }else{
        echo "編集番号かパスワードが空欄になっています<br/>";
    }
}

if(isset($_POST['delete']) && isset($_POST['password'])){
    if(strlen($_POST['delete']) && strlen($_POST['password'])){
        $delete_id = $_POST['delete'];
        $password = $_POST['password'];
        $stmt = $pdo->prepare('SELECT * FROM post_table_apply WHERE id = :id');
        $stmt->execute(array(':id' => $delete_id));
        $delete_post = $stmt->fetch(PDO::FETCH_ASSOC);
        if($delete_post['password'] == $password){
            $stmt = $pdo->prepare('DELETE FROM post_table_apply WHERE id=:id');
            $stmt->execute(array(':id' => $delete_id));
            echo $delete_id."番の投稿を削除しました<br/>";
        }else{
            echo "削除パスワードが間違っています<br/>";
        }
    }else{
        echo "削除番号かパスワードが空欄になっています<br/>";
    }
}

if(isset($_POST['comment']) && isset($_POST['name']) && isset($_POST['password'])){
    if(strlen($_POST['comment']) && strlen($_POST['name']) && strlen($_POST['password'])){
        $comment = $_POST['comment'];
        $name = $_POST['name'];
        $password = $_POST['password'];
        $date = date("Y-m-d");
        $stmt = $pdo->prepare('INSERT INTO post_table_apply (name, comment, date, password) VALUES (:name, :comment, :date, :password)');
        $flag = $stmt->execute(array(':name' => $name, ':comment' => $comment, ':date' => $date, ':password' => $password));
        if ($flag){
            print('投稿しました<br>');
        }else{
            print('投稿に失敗しました<br>');
        }
    }else{
        echo "未入力の欄があります<br/>";
    }
}elseif(isset($_POST['comment']) && isset($_POST['name']) && isset($_POST['edit_id'])){
    if(strlen($_POST['comment']) && strlen($_POST['name']) && strlen($_POST['edit_id'])){
        $comment = $_POST['comment'];
        $name = $_POST['name'];
        $date = date("Y-m-d");
        $edit_id = $_POST['edit_id'];
        $stmt = $pdo->prepare("UPDATE post_table_apply SET name = :name, comment = :comment, date = :date WHERE id = :id");
        $stmt->execute(array(':name' => $name, ':comment' => $comment, ':date' => $date, ':id' => $edit_id));
        $edit_id = -10000;
    }else{
        echo "未入力の欄があります<br/>";
    }
}

echo "投稿一覧<br/>";
$result_rows = $pdo->query('SELECT * FROM post_table_apply');
foreach ( $result_rows as $row ) {
    echo "{$row['id']}";
    echo " {$row['name']}";
    echo " {$row['comment']}";
    echo " {$row['date']}";
    echo "<br/>";
}
echo "<br/>";
?>
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>投稿フォーム</h1>
    <form action="kadai3_top.php" method="post">
    <p>名前</p>
    <input type = "text" name ="name" value="<?php if(isset($edit_name)){echo $edit_name;} ?>"><br/>
    <p>コメント</p>
    <input type = "text" name ="comment" value="<?php if(isset($edit_txt)){echo $edit_txt;} ?>"><br/>
    <?php if(!isset($edit_id) || $edit_id == -10000){
    ?>
        <p>パスワード</p>
        <input type = "text" name ="password"><br/>
    <?php
    }
    ?>
    <input type="hidden" name ="edit_id" value="<?php if(isset($edit_id)){echo $edit_id;} ?>">
    <input type = "submit" value ="送信">
    </form>
    <script>
    function delete_confirm() {
            var select = confirm("削除してよろしいですか?");
            return select;
    }
    </script>
    <h1>削除</h1>
    <p>削除する投稿の番号</p>
    <form action="kadai3_top.php" method="post" onsubmit="return delete_confirm()">
    <input type = "text" name ="delete"><br/>
    <p>パスワード</p>
    <input type = "text" name ="password"><br/>
    <input type = "submit" value ="送信">
    </form>
    <h1>編集</h1>
    <p>編集する投稿の番号</p>
    <form action="kadai3_top.php" method="post">
    <input type = "text" name ="edit"><br/>
    <p>パスワード</p>
    <input type = "text" name ="password"><br/>
    <input type = "submit" value ="送信"><br/>
    <a href="http://co-19-271.99sv-coco.com/kadai3_1_signup.php">新規登録</a>
    </form>
</body>
</html>
anonymous No title
PHP
<?php
$pdo = new PDO('mysql:host=localhost;dbname=co_19_271_99sv_coco_com', 'co-19-271.99sv-c', 'Xc5tnWDA');
$pdo->query('CREATE TABLE foo_table (id INT, name VARCHAR(20))');
$pdo->query('CREATE TABLE foo_table_2 (id INT, name VARCHAR(20))');
$show = $pdo->query('SHOW TABLES from co_19_271_99sv_coco_com');
while($re = $show->fetch(PDO::FETCH_ASSOC)){
    var_dump($re);
    echo "<br/>";
}
echo "データ入力<br/>";
$pdo->query('INSERT INTO foo_table (id, name) VALUES (3, "kido")');
$result_rows = $pdo->query('SELECT * FROM foo_table');
foreach ( $result_rows as $row ) {
    echo "id: {$row['id']}";
    echo "name: {$row['name']}";
    echo "<br/>";
}
echo "<br/>";
echo "データ更新<br/>";
$stmt = $pdo->prepare("UPDATE foo_table SET name = :name WHERE id = :id");
$stmt->bindValue(':id', 3, PDO::PARAM_INT);
$stmt->bindValue(':name', 'tanaka', PDO::PARAM_STR);
$stmt->execute();
$result_rows = $pdo->query('SELECT * FROM foo_table');
foreach ( $result_rows as $row ) {
    echo "id: {$row['id']}";
    echo "name: {$row['name']}";
    echo "<br/>";
}
echo "<br/>";
echo "データ削除<br/>";
$stmt = $pdo->prepare('DELETE FROM foo_table WHERE id=:id');
$stmt->execute(array(':id' => 3));
$result_rows = $pdo->query('SELECT * FROM foo_table');
foreach ( $result_rows as $row ) {
    echo "id: {$row['id']}";
    echo "name: {$row['name']}";
    echo "<br/>";
}
echo "<br/>";

?>
anonymous No title
PHP
<?php
$filename = "kadai2_2.txt";
if(isset($_GET['comment']) && isset($_GET['name'])){
    $comment = $_GET['comment'];
    $name = $_GET['name'];
    if(file_exists($filename)){
        $fp = fopen($filename, "a");
        fwrite($fp, count(file($filename))+1);
    }else{
        $fp = fopen($filename, "w");
        fwrite($fp, "1");
    }
    fwrite($fp, "<>");
    fwrite($fp, $name."<>");
    fwrite($fp, $comment."<>");
    fwrite($fp, date("Y-m-d")."\n");
    fclose($fp);
}
?>
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="kadai2_2.php" method="get">
    <p>名前</p>
    <input type = "text" name ="name"><br/>
    <p>コメント</p>
    <input type = "text" name ="comment"><br/>
    <input type = "submit" value ="送信">
    </form>
</body>
</html>
anonymous No title
PHP
<?php
$pdo = new PDO('mysql:host=localhost;dbname=***', '***', '***');
$pdo->query('CREATE TABLE IF NOT EXISTS post_table_apply (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(20),
    comment TEXT,
    date DATE,
    password VARCHAR(20)
    )');

if(isset($_POST['edit']) && isset($_POST['password'])){
    if(strlen($_POST['edit']) && strlen($_POST['password'])){
        $password = $_POST['password'];
        $stmt = $pdo->prepare('SELECT * FROM post_table_apply WHERE id = :id');
        $stmt->execute(array(':id' => $_POST['edit']));
        $edit_post = $stmt->fetch(PDO::FETCH_ASSOC);
        if($edit_post['password'] == $password){
            $edit_id = $_POST['edit'];
            $edit_name = $edit_post['name'];
            $edit_txt = $edit_post['comment'];
        }else{
            echo "編集パスワードが間違っています<br/>";
        }
    }else{
        echo "編集番号かパスワードが空欄になっています<br/>";
    }
}

if(isset($_POST['delete']) && isset($_POST['password'])){
    if(strlen($_POST['delete']) && strlen($_POST['password'])){
        $delete_id = $_POST['delete'];
        $password = $_POST['password'];
        $stmt = $pdo->prepare('SELECT * FROM post_table_apply WHERE id = :id');
        $stmt->execute(array(':id' => $delete_id));
        $delete_post = $stmt->fetch(PDO::FETCH_ASSOC);
        if($delete_post['password'] == $password){
            $stmt = $pdo->prepare('DELETE FROM post_table_apply WHERE id=:id');
            $stmt->execute(array(':id' => $delete_id));
            echo $delete_id."番の投稿を削除しました<br/>";
        }else{
            echo "削除パスワードが間違っています<br/>";
        }
    }else{
        echo "削除番号かパスワードが空欄になっています<br/>";
    }
}

if(isset($_POST['comment']) && isset($_POST['name']) && isset($_POST['password'])){
    if(strlen($_POST['comment']) && strlen($_POST['name']) && strlen($_POST['password'])){
        $comment = $_POST['comment'];
        $name = $_POST['name'];
        $password = $_POST['password'];
        $date = date("Y-m-d");
        $stmt = $pdo->prepare('INSERT INTO post_table_apply (name, comment, date, password) VALUES (:name, :comment, :date, :password)');
        $flag = $stmt->execute(array(':name' => $name, ':comment' => $comment, ':date' => $date, ':password' => $password));
        if ($flag){
            print('投稿しました<br>');
        }else{
            echo $flag;
            print('投稿に失敗しました<br>');
        }
    }else{
        echo "未入力の欄があります<br/>";
    }
}elseif(isset($_POST['comment']) && isset($_POST['name']) && isset($_POST['edit_id'])){
    if(strlen($_POST['comment']) && strlen($_POST['name']) && strlen($_POST['edit_id'])){
        $comment = $_POST['comment'];
        $name = $_POST['name'];
        $date = date("Y-m-d");
        $edit_id = $_POST['edit_id'];
        $stmt = $pdo->prepare("UPDATE post_table_apply SET name = :name, comment = :comment, date = :date WHERE id = :id");
        $stmt->execute(array(':name' => $name, ':comment' => $comment, ':date' => $date, ':id' => $edit_id));
        $edit_id = -10000;
    }else{
        echo "未入力の欄があります<br/>";
    }
}

echo "投稿一覧<br/>";
$result_rows = $pdo->query('SELECT * FROM post_table_apply');
foreach ( $result_rows as $row ) {
    echo "{$row['id']}";
    echo " {$row['name']}";
    echo " {$row['comment']}";
    echo " {$row['date']}";
    echo "<br/>";
}
echo "<br/>";
?>
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>投稿フォーム</h1>
    <form action="kadai2_apply.php" method="post">
    <p>名前</p>
    <input type = "text" name ="name" value="<?php if(isset($edit_name)){echo $edit_name;} ?>"><br/>
    <p>コメント</p>
    <input type = "text" name ="comment" value="<?php if(isset($edit_txt)){echo $edit_txt;} ?>"><br/>
    <?php if(!isset($edit_id) || $edit_id == -10000){
    ?>
        <p>パスワード</p>
        <input type = "text" name ="password"><br/>
    <?php
    }
    ?>
    <input type="hidden" name ="edit_id" value="<?php if(isset($edit_id)){echo $edit_id;} ?>">
    <input type = "submit" value ="送信">
    </form>
    <script>
    function delete_confirm() {
            var select = confirm("削除してよろしいですか?");
            return select;
    }
    </script>
    <h1>削除</h1>
    <p>削除する投稿の番号</p>
    <form action="kadai2_apply.php" method="post" onsubmit="return delete_confirm()">
    <input type = "text" name ="delete"><br/>
    <p>パスワード</p>
    <input type = "text" name ="password"><br/>
    <input type = "submit" value ="送信">
    </form>
    <h1>編集</h1>
    <p>編集する投稿の番号</p>
    <form action="kadai2_apply.php" method="post">
    <input type = "text" name ="edit"><br/>
    <p>パスワード</p>
    <input type = "text" name ="password"><br/>
    <input type = "submit" value ="送信">
    </form>
</body>
</html>
Don't you submit code?
Submit