anonymous No title
PHP
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <title>mission_3-3</title>
</head>

<body>
    <form action="" method="post">
        <!--<input type="str" name="str" placeholder="コメント">         -->
        <!--<input type="submit" name="submit">-->
        <b>投稿フォーム</b>
        <p>お名前:
	    <input type="name" name="name"></p>
	    <p>コメント:
	    <input type="str" name="comment"></p>
	    <input type="submit" name="submit"><br><br>
	    
	    <b>削除フォーム</b>
	    <p>投稿番号:
	    <input type="text" name="deletenumber"></p>
        <input type="submit" name="delete" value="削除"><br><br>
        
    </form>
    
<?php

//  投稿フォーム  

    $name = $_POST["name"];
    $str = $_POST["comment"]; //変数$strの定義
    $date = date("Y/m/d H:i:s");
    $filename="mission_3-2.txt";
    $num = count( file( $filename ) ); // ファイルのデータの行数を数えて$numに代入
    $num++; // 投稿番号を取得
    $data = $num."<>".$name."<>".$str."<>".$date."\n";
    
    if(!empty($name && $str))  
{ 
    $fp = fopen($filename,"a");
    fwrite($fp, $data);
    fclose($fp);
}    
   
 
//   削除フォーム  

if($_POST["delete"])
    { //削除ボタンが押されたら処理
    
        $delete = $_POST["deletenumber"];
        
        $deletefile = file($filename); //ファイルを全て配列に入れる
        $fp = fopen($filename, "w");
        
        foreach($contents as $content) 
        {
            $de_lete = explode("<>", $content); //1行ずつ配列に入れる
            if($de_lete[0] != $delete)
            {
                fwrite($fp,$content);
            }
            else
            {
               fwrite($fp,"".PHP_EOL); //""で削除できる
            } 
    
        }
        fclose($fp);
    }
    
   
// 表示    
    
    $contents = file($filename); //txtファイルを読み込む
        
        foreach($contents as $content)
        {//ループ処理
            $line = explode("<>",$content);
                echo $line[0]." ".$line[1]." ".$line[2]." ".$line[3]."<br>";
        }

?>    
</body>
</html>
anonymous 簡易掲示板
PHP
<?php
//http://co-19-301.99sv-coco.com/kadai/kadai2/kadai2_advanced_level.php
$dsn      = 'mysql:dbname=co_19_301_99sv_coco_com;host=localhost';
$user     = 'co-19-301.99sv-coco_c';
$password_db = 'Em4kxvSU';

try{
  $dbh = new PDO($dsn, $user, $password_db);
  $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

}catch(PDOException $e){
  print("データベースの接続に失敗しました".$e->getMessage());
  die();
}

$isEditMode = 0;
$edit_id = 0;
/////////////////// 入力された名前とコメントのデータを取得 ////////////////
if (isset($_POST["name"]) && isset($_POST["comment"])) {
  if($_POST["name"] != "" && $_POST["comment"] != "") {

    $_normalAddMode = true;
    $edit_id = $_POST["edit_id"];
    
    if ($edit_id) {
      $time = date("Y-m-d H:i:s");
      $name = $_POST["name"];
      $comment = $_POST["comment"];
      $password = $_POST["password"];

      try {
        // クエリの作成(UPDATE)
        $query = 'UPDATE kadai2_MySQL_TEST SET name = :name, comment = :comment, time = :time, password = :password WHERE id = :id';
        $stmt = $dbh->prepare($query);
        // 実行
        $stmt->execute(array(':name' => $name, ':comment' => $comment, ':time' => $time, ':password' => $password, ':id' => $edit_id));
      }catch(PDOException $e){
        print("データベースの接続に失敗しました");
        die();
      }
      
      $_normalAddMode = false;
      $isEditMode = 0;
    }
    
    if ($_normalAddMode) {
      if($_POST["password"] != "") {

        // $fp = fopen("input_data_with_password.txt", "a+");
        
        $time = date("Y-m-d H:i:s");
        $name = $_POST["name"];
        $comment = $_POST["comment"];
        $password = $_POST["password"];
        try{
          $dbh = new PDO($dsn, $user, $password_db);
          $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
          // クエリの作成(INSERT)
          $query = 'INSERT INTO kadai2_MySQL_TEST(name, comment, time, password) VALUES(:name, :comment, :time, :password)';
          $stmt = $dbh->prepare($query);
                
          $stmt -> bindValue(':name', $name, PDO::PARAM_STR_CHAR);
          $stmt -> bindValue(':comment', $comment, PDO::PARAM_STR_CHAR);
          $stmt -> bindValue(':time', (string)$time, PDO::PARAM_STR_CHAR);
          $stmt -> bindValue(':password', $password, PDO::PARAM_STR_CHAR);
                
          // 実行
          $stmt->execute();
        
        }catch(PDOException $e){
          print("データベースの接続に失敗しました");
          die();
        }
      }
    }
    
  }

}

/////////////////// 指定された番号のコメントを削除 ////////////////
if (isset($_POST["delete_number"]) && isset($_POST["password_delete"])) {

  $delete_number = $_POST["delete_number"];

  $password_delete = $_POST["password_delete"];
  $password_delete_check = "";
  try {
    // 入力された番号に対応したidを見つける
    $query = 'SELECT * FROM kadai2_MySQL_TEST';
    $stmt = $dbh->query($query);
    $count = 0;
    $delete_id = 0;
    while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
      $count++;
      $id = $row["id"];
      if ($delete_number == $count) $delete_id = $id;
    }

    // クエリの実行(SELECT)
    $query = 'SELECT * FROM kadai2_MySQL_TEST WHERE id =' . $delete_id;
    $stmt = $dbh->query($query);
    // チェック用のPassword
    while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
      $password_delete_check = $row["password"];
    }
  
    if ($password_delete == $password_delete_check) {
      // クエリの作成(DELETE)
      $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      $query = 'DELETE FROM kadai2_MySQL_TEST WHERE id = :id';
      $stmt = $dbh->prepare($query);
      // 実行
      $stmt->execute(array(':id' => $delete_id));

    }
    else if ($password_delete_check == "") echo "<script type='text/javascript'>alert('対象のコメントがありません。');</script>"; 
    else echo "<script type='text/javascript'>alert('パスワードが違います。');</script>"; 

  }catch(PDOException $e){
    print("データベースの接続に失敗しました");
    die();
  }
}

/////////////////// 指定された番号のコメントを表示(edit) ////////////////
if (isset($_POST["edit_number"]) && isset($_POST["password_edit"])) {
  
  $password_edit = $_POST["password_edit"];
  $password_edit_check = "";

  $edit_number = $_POST["edit_number"];

  try {
    // 入力された番号に対応したidを見つける
    $query = 'SELECT * FROM kadai2_MySQL_TEST';
    $stmt = $dbh->query($query);
    $count = 0;
    $edit_id = 0;
    while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
      $count++;
      $id = $row["id"];
      if ($count == $edit_number) $edit_id = $id;
    }

    $query = 'SELECT * FROM kadai2_MySQL_TEST WHERE id = ' . $edit_id;
    $stmt = $dbh->query($query);
  
    while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
      $name_form = $row["name"];
      $comment_form = $row["comment"];
      $password_form = $row["password"];
      $password_edit_check = $row["password"];
    }
     
    if ($password_edit == $password_edit_check) $isEditMode = $edit_id;
    else if ($password_delete_check == "") echo "<script type='text/javascript'>alert('対象のコメントがありません。');</script>"; 
    else echo "<script type='text/javascript'>alert('パスワードが違います。');</script>";

  }catch(PDOException $e){
    print("データベースの接続に失敗しました");
    die();
  }

}

// 接続を閉じる
$dbh = null;
?>

<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="UFT-8">
    <title>簡易掲示板</title>
    <link rel="stylesheet" type="text/css" href="index.css">
    <script type="text/javascript">
      function check(){
      	if(confirm('削除してよろしいですか?')){
      		return true;
      	}
      	else{
      		alert('キャンセルされました');
      		return false;
      	}
      }
    </script>
  </head>
<body>
  <div class="container">

    <h1>簡易掲示板</h1>
    <form action="kadai2_advanced_level.php" method="post">
      <input type="hidden" value=<?php echo $isEditMode; ?> name="JugeEditMode_inInputForm">
      <input type="hidden" value=<?php echo $edit_id; ?> name="edit_id" >
      <div class="form-element">
        <p>名前:</p>
        <input type="text" name="name" value=<?php
          if ($isEditMode) echo $name_form;
          else echo "";
        ?> >
      </div>
      <div class="form-element">
        <p>コメント:</p>
        <input type="text" name="comment" value=<?php
          if ($isEditMode) echo $comment_form;
          else echo "";
        ?> >
      </div>
      <div class="form-element set_btn">
        <p>パスワード:</p>
        <input type="password" name="password" value=<?php
          if ($isEditMode) echo $password_form;
          else echo ""; ?> >
        <button class="btn-submit" type="submit">投稿</button>
      </div>
      <div class="comment_lineup">
        <?php 
          echo '<div class="info ex">';
          echo '<p class="main_info">ID : id, <span style="font-weight: bold;"> 名前 </span><span style="font-weight: bold;">「コメント」</span> </p><p class="time_info">時間</p>';
          echo "</div>";
          $count = 1;
          try{
            $dbh = new PDO($dsn, $user, $password_db);
            $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            // クエリの実行(SELECT)
            $query = 'SELECT * FROM kadai2_MySQL_TEST';
            $stmt = $dbh->query($query);          
            // 表示処理
            while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
              $id = $row["id"];
              $name = $row["name"];
              $comment = $row["comment"];
              $time = $row["time"];
      
              echo '<div class="info">';
              echo '<p class="main_info">ID : ' . $count . ', <span style="font-weight: bold;"> ' . $name . "</span>" . '<span style="font-weight: bold;">「' . $comment . '」</span> </p><p class="time_info">' . $time."</p>";
              echo "</div>";
              $count++;
            }
          
          }catch(PDOException $e){
            print("データベースの接続に失敗しました");
            die();
          }

          $dbh = null;
          ?>
      </div>
    </form>
    <form class="form_mini" action="kadai2_advanced_level.php" method="post" onsubmit="return check()">
      <div class="form-element">
        <p>削除番号:</p><input type="number" name="delete_number">
      </div>
      <div class="form-element set_btn">
        <p>パスワード:</p>
        <input type="password" name="password_delete">
        <button class="btn-submit" type="submit">削除</button>
      </div>
    </form>
    <form class="form_mini" action="kadai2_advanced_level.php" method="post">
      <div class="form-element">
        <input type="hidden" value=<?php echo $isEditMode; ?> name="JugeEditMode">
        <p>編集番号:</p><input type="number" name="edit_number">
      </div>
      <div class="form-element set_btn">
        <p>パスワード:</p>
        <input type="password" name="password_edit">
        <button class="btn-submit" type="submit">番号を指定</button>
      </div>
    </form>
  
  </div>
  </body>
</html>
anonymous No title
PHP
<html>
  <head>
    <title>簡易掲示板</title>
  </head>
  <script>
    function confirm_delete_func() {
        var select = confirm("本当に削除しますか?");
        return select;
    }
    function aleart_password() {
        aleart("パスワードが一致しません");
    }
  </script>
  <body>
    <h1>form</h1>
    <?php

      // データベース接続
      $url = "localhost";
      $user = "root";
      $pass = "D4agc9yf";
      $db = "co_19_295_99sv_coco_com";
      $link = mysqli_connect($url, $user, $pass, $db);

      // 接続エラー確認
      if( mysqli_connect_errno($link) ) {
        echo mysqli_connect_errno($link).':'.mysqli_connect_error($link);
      }
      // 文字コード設定
      mysqli_set_charset($link, "utf8");

      $filename = "kadai2_2.txt";
      if(!file_exists($filename)){ // 初回ファイル作成
        touch("kadai2_2.txt");
        $num = 1;
      }
      if(isset($_POST['button-post'])){ // 投稿
        if(!empty($_POST['name']) && !empty($_POST['comment']) && !empty($_POST['password'])){
          if(!empty($_POST['status'])){ // DBの編集
            $sql1 = "UPDATE form SET name = ?, comment = ?, date = ?, password = ? WHERE number = ?";
            if ($stmt1 = $link->prepare($sql1)) {
              $name = $_POST['name'];
              $comment = $_POST['comment'];
              $date = date("Y-m-d");
              $password = $_POST['password'];
              $stmt1->bind_param("sssss", $name, $comment, $date, $password, $_POST['status']);
            }
            $stmt1->execute();
          }else{
            // 最後に投稿された投稿番号+1を取得
            $sql0 = "SELECT number FROM form ORDER BY number DESC LIMIT 1";
            if ($result = $link->query($sql0)) {
              while($row = $result->fetch_assoc()) {
                $numnum = $row['number'];
              }
              $result->close();
            }
            if(!isset($numnum)){
              $numnum = 1;
            }else{
              $numnum = $numnum + 1;
            }

            // DBに追加
            $sql1 = "INSERT INTO form VALUES (?,?,?,?,?)";
            if ($stmt1 = $link->prepare($sql1)) {
              $name = $_POST['name'];
              $comment = $_POST['comment'];
              $date = date("Y-m-d");
              $password = $_POST['password'];
              $stmt1->bind_param("sssss", $numnum, $name, $comment, $date, $password);
            }
            $stmt1->execute();
          }
        }
      }else if(isset($_POST['button-edit']) && isset($_POST['confirmpasswordEdit'])){ // 編集(passwordあり)
        if(!empty($_POST['edit-number'])){
          // password確認
          $sql2 = "SELECT password FROM form WHERE number = ?";
          if ($stmt = $link->prepare($sql2)) {
            $editNum = $_POST['edit-number'];
            $stmt->bind_param("s", $editNum);
          }
          $stmt->execute();
          $stmt->bind_result($password); // 結果変数をバインド
          $stmt->fetch(); // 値を取得

          if($password==$_POST['confirmpasswordEdit']){
            $delete = 1;
          }
          $stmt->close(); // ステートメントを閉じる

          // passwordが一致した場合編集処理
          if($delete == 1){            
            $sql2 = "SELECT name,comment,password FROM form WHERE number = ?";
            if ($stmt = $link->prepare($sql2)) {
              $editNum = $_POST['edit-number'];
              // echo $_POST['edit-number'];
              // print(gettype($editNum));
              $stmt->bind_param("s", $editNum);
            }
            $stmt->execute();
            $stmt->bind_result($name,$comment,$password); // 結果変数をバインド
            $stmt->fetch(); // 値を取得

            $editName = $name;
            $editComment = $comment;
            $editPassword = $password;

            $stmt->close(); // ステートメントを閉じる
          }else{
            echo '<script type="text/javascript">alert("パスワードが違います");</script>';
          }
        }
      }else if(isset($_POST['button-delete']) && isset($_POST['confirmpasswordDelete'])){ // 削除(passwordあり)
        if(!empty($_POST['delete-number'])){

          // password確認
          $sql2 = "SELECT password FROM form WHERE number = ?";
          if ($stmt = $link->prepare($sql2)) {
            $deleteNum = $_POST['delete-number'];
            $stmt->bind_param("s", $deleteNum);
          }
          $stmt->execute();
          $stmt->bind_result($password); // 結果変数をバインド
          $stmt->fetch(); // 値を取得

          if($password==$_POST['confirmpasswordDelete']){
            $delete = 1;
          }
          $stmt->close(); // ステートメントを閉じる
          
          // passwordが一致した場合削除処理
          if($delete == 1){
            $sql1 = "DELETE FROM form WHERE number = ?";
            if ($stmt1 = $link->prepare($sql1)) {
              $stmt1->bind_param("s", $_POST['delete-number']);
            }
            $stmt1->execute();
          }else{
            echo '<script type="text/javascript">alert("パスワードが違います");</script>';
          }
        }
      }
      $total_list = "";
      $sql = "SELECT * FROM form";
      // クエリ文を実行し、結果を$resultに入れる
      if($result = mysqli_query($link, $sql)) {
        // 表示用の$total_listに代入
        while($row = mysqli_fetch_assoc($result)) {
          $total_list .= "<tr>".
          "<td>".$row['number']."</td>".
          "<td>".$row['name']."</td>".
          "<td>".$row['comment']."</td>".
          "<td>".$row['date']."</td>".
          "</tr>";
        }
        // 実行結果をクリア
        mysqli_free_result($result);
      }
      // データベースとの接続解除
      mysqli_close($link);
    ?>
    <h1>投稿フォーム</h1>
    <form action="kadai2_oyo.php" method="post">
      名前:<input type="text" name="name" value = "<?php if(!empty($editName)){echo $editName;}?>"><br>
      コメント:<input type="text" name="comment" value = "<?php if(!empty($editComment)){echo $editComment;}?>"><br>
      パスワード:<input type="text" name="password" value = "<?php if(!empty($editPassword)){echo $editPassword;}?>"><br>
      <input type="hidden" name="status" value="<?php if(!empty($editNum)){echo $editNum;}?>">
      <?php 
      if(isset($_POST['button-post'])){ // 投稿
        if(empty($_POST['name']) || empty($_POST['comment']) || empty($_POST['password'])){
          echo "名前・コメント・パスワードを全て入力してください<br />";
        }
      }
      ?>
      <input type="submit" name="button-post" value="投稿">
    </form>
    <h1>編集フォーム</h1>
    <form action="kadai2_oyo.php" method="post">
      編集番号:<input type="text" name="edit-number" value = "<?php if(!empty($_POST['edit-number'])){echo $_POST['edit-number'];}?>">
      <input type="submit" name="button-edit-request" value="編集"><br>
      <?php
      if(isset($_POST['button-edit-request'])){
        if(!empty($_POST['edit-number'])){
          echo "<input type='text' name='confirmpasswordEdit' placeholder='password'>";
          echo "<input type='submit' name='button-edit' value='確定'>";
        }else{
          echo "編集番号を入力してください";
        }
      }
      ?>
    </form>
    <h1>削除フォーム</h1>
    <form action="kadai2_oyo.php" method="post">
      削除番号:<input type="text" name="delete-number" value = "<?php if(!empty($_POST['delete-number'])){echo $_POST['delete-number'];}?>">
      <input type="submit" name="button-delete-request" value="削除"><br>
      <?php
      if(isset($_POST['button-delete-request'])){
        if(!empty($_POST['delete-number'])){
          echo "<input type='text' name='confirmpasswordDelete' placeholder='password'>";
          echo "<input type='submit' name='button-delete' value='確定' onclick='return confirm_delete_func()'>";
        }else{
          echo "削除番号を入力してください";
        }
      }
      ?>
    </form>
    <h1>投稿一覧</h1>
    <!-- テ ー ブ ル の 作 成 -->
    <table border=4>
      <tr bgcolor="#cccccc">
      <th>番号</th>
      <th>名前</th>
      <th>コメント</th>
      <th>投稿日</th>
      </tr>
      <?php echo $total_list ?>
    </table>
  </body>
</html>
anonymous No title
PHP
<?php
 fscanf(STDIN,"%d%d",$r,$c);
 $ans = 0;
 $total = 0;
 $nums = [];
 
 for($i=0;$i<$r;$i++){
     
    $line = trim(fgets(STDIN));
    $nums_line = array_map("intval",explode(" ",$line));
    
    for($j=0;$j<$c;$j++){
    $nums[$j] += $nums_line[$j];
    }
    
    for($k=0;$k<$c;$k++){
      $ans += $nums_line[$k];
     }

    $total += $ans;
    echo $line." ".$ans.PHP_EOL;
    $ans = 0;
 }
 
    $str="";
    for($l=0;$l<$c;$l++){
        $str .= $nums[$l]." ";
    }
    
   echo $str.$total.PHP_EOL;
 
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>分数の計算を行う</title>
</head>

<body>
  <h1>分数の計算を行います</h1>
  <form action="index.php" method="POST">
    分数① <input type="text" name="molecule1" required> /
    <input type="text" name="denominator1" required>
    <br>
    <br>
    分数② <input type="text" name="molecule2" required> /
    <input type="text" name="denominator2" required>
    <hr>
    <input type="submit" value="分数①+分数②">
  </form>

  <?php if (isset($_POST['molecule1'])) : ?>
    <?php
    $molecule1 = $_POST['molecule1'];
    $denominator1 = $_POST['denominator1'];
    $molecule2 = $_POST['molecule2'];
    $denominator2 = $_POST['denominator2'];

    $denominator = $denominator1 * $sdenominator2;
    $molecule = ($molecule1 * $denominator2) + ($molecule2 * $denominator1);

    echo '分数① ' . $molecule1 . '/' . $denominator1 . ' と ';
    echo '分数② ' . $molecule2 . '/' . $denominator2 . ' 計算結果 ';
    $num1 = $molecule;
    $num2 = $denominator;
    ?>
    <?php while ($num1 % $num2 !== 0) : ?>
      <?php
      $num3 = $num1 % $num2;
      $num1 = $num2;
      $num2 = $num3;
      ?>
    <?php endwhile; ?>

    <?php
    $molecule /= $num2;
    $denominator /= $num2;
    $integer = (int) ($molecule / $denominator);
    ?>
    <?php if ($molecule < $denominator) : ?>
      <?= '分数だけ' . $molecule . '/' . $denominator; ?>
    <?php elseif ($molecule % $denominator === 0) : ?>
      <?= '整数だけ' . $integer; ?>
    <?php else : ?>
      <?= '帯分数' . $integer . ' ' .  ($molecule - $integer * $denominator) . '/' . $denominator; ?>
    <?php endif; ?>
  <?php endif; ?>
</body>

</html>
anonymous No title
PHP
//新規投稿処理
<?php
 $name=$_POST["name"];
 $com=$_POST["comment"];
 $pass=$_POST["pass"];
 $date=date("Y-m-d");
 $a = fopen("2_6.kadai.txt", "a");
 $b = fopen("2_6_fordelete.kadai.txt", "a");
 $c = fopen("2_6.kadai.public.txt", "a");
 $num = count( file( "2_6.kadai.txt" ) );
 $num++;
 if(isset($_POST["comment"]) && isset($_POST["name"]) && !isset($_POST["delete"])&& isset($_POST["pass"])){
	fwrite($a,  $num. "<>". $name. "<>". $com. "<>". $date."<>". "$pass". "<>". "\r\n");
	fclose($a);
}
 if(isset($_POST["comment"]) && isset($_POST["name"]) && !isset($_POST["delete"])&& isset($_POST["pass"])){
	fwrite($b,$name. "<>". $com. "<>". $date."<>". "$pass"."<>". "\r\n");
	fclose($b);
}
 if(isset($_POST["comment"]) && isset($_POST["name"]) && !isset($_POST["delete"])&& isset($_POST["pass"])){
	fwrite($c,$num. "<>" . $name. "<>". $com. "<>". $date."<>"."\r\n");
	fclose($c);
}
?>


anonymous No title
PHP
//最初のページ.新規投稿や編集を受け付ける.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>kadai_4</title>
</head>
<body>
<form method="POST" action="2kadai_6.1.php">
	<label>入力フォームの送信:</label><br />
	<label>名前:</label>
	<input type="text" name="name" /><br />
	<label>コメント:</label>
	<input type="text" name="comment" /><br />
	<label>パスワード設定:</label><br />
	<input type = "text" name="pass" /><br />
	<input type="submit" value="送信" /><br />
</form>
<form method="POST" action="foredit.php">
	<input type="submit" value="削除" onClick="disp()"/><br />
<script type="text/javascript">
<!--

function disp(){

	window.alert('本当に削除しますか?');

}

// -->

</script>
</form>
<form method="POST" action="foredit.php">
	<input type="submit" value="編集" onClick="disp()"/><br />
<script type="text/javascript">
<!--

function disp(){

	window.alert('本当に編集しますか?');

}

// -->
</script>
</form>
<?php
$file = fopen("2_6.kadai.public.txt", "r");
if($file){
	while ($line= fgets($file)) {
		$a = explode("<>",$line);
		foreach($a as $key=>$value){
			echo $value. "-";
		};
		echo "<br>\r\n";
	};
}
fclose($file)
?>
</body>
</html>
//編集処理をクリックされた場合に遷移するページ.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>パスワード入力</title>
</head>
<body>
<?php 
if(isset($POST_["delete"])){
echo $POST_["delete"];}elseif(isset($POST_["editnum"])){
echo $POST_["editnum"];};
?>
<p>パスワードを入力してください. </p>
<form method="POST" action="login.php">
<input type="text" name="input"><br />
<input type="submit" value="送信" /><br />
</form>
</body>
</html>
//ログイン画面
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>編集確認用</title>
</head>
<body>
<form method="POST" action="2kadai_6.edit0.php" />
	<label>投稿番号</label><br/>
	<textarea readonly name="editnumber" rows="1" cols="10">
	<?php
	$pass =$_POST["input"];
$file = fopen("2_6.kadai.txt", "r");
$array = array();
while($line = fgets($file)){
$a = explode("<>", $line);
$array[$a[0]] = $a[4];
}
	echo $a[0];
	?>
</textarea>
</form>
<?php
$pass =$_POST["input"];
$file = fopen("2_6.kadai.txt", "r");
$array = array();
while($line = fgets($file)){
$a = explode("<>", $line);
$array[$a[0]] = $a[4];
}
if(in_array($pass, $array)){
header('Location: 
\\FTP情報を含むので一応隠しますが, ここについてはエラーは出ていません.
');
exit;
}else{
echo "パスワードが違います. ";
};
?>
</body>
</html>
//ログイン成功後に接続予定の画面
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>編集確認用</title>
</head>
<body>
<p><?php
 $editno=$_POST["editnumber"];
 $fd= file("2_6_fordelete.kadai.txt");
 $fp= fopen("2_6_fordelete.kadai.txt", "r");
 $fpp= fopen("2_6.kadai.txt", "r");
 $data = $fd[(int)$editno-1];
 $edit = explode($data, "<>");
 if(array_key_exists((int)$editno-1, $fd)){echo "指定番号の投稿あり";}else{echo "指定番号の投稿なし";};
?></p>
<form method = "POST" action="2kadai_6.edit2.php">
	<label>投稿内容の確認</label><br />
	<input type ="hidden" name="veredit" value="true"><br />
	<label>投稿番号</label><br/>
	<textarea readonly name="editnumber" rows="1" cols="10">
	<?php
	$editno=$_POST["editnumber"];
	echo $editno;
	?>
	</textarea><br/>
	<label>名前:</label><br />
	<textarea name="rename" cols="10" rows="1">
<?php
$editno=$_POST["editnumber"];
$fd= file("2_6_fordelete.kadai.txt");
$fp= fopen("2_6_fordelete.kadai.txt", "r");
$fpp= fopen("2_6.kadai.txt", "r");
$data = $fd[(int)$editno-1];
$edit = explode("<>", $data);
if(array_key_exists((int)$editno-1, $fd)){
	echo $edit[0];};
?>
	</textarea><br />
	<label>コメント:</label><br />
	<textarea name="recomment" cols="50" rows="10">
<?php
$editno=$_POST["editnumber"];
$fd= file("2_6_fordelete.kadai.txt");
$fp= fopen("2_6_fordelete.kadai.txt", "r");
$fpp= fopen("2_6.kadai.txt", "r");
$data = $fd[(int)$editno-1];
$edit = explode("<>", $data);
if(array_key_exists((int)$editno-1, $fd)){
	echo $edit[1];};
?>
	</textarea><br />
	<input type="submit" value="送信" /><br />
</form>
</body>
</html>
//現状だと$_POST["editnum"]に情報が遅れていないのでエラーになります.上のログイン画面からどのように情報を送ればよいのかがわからない,という質問です. 
//受け付けた編集の処理
<?php
 $id = $_POST["veredit"];
 $editno=$_POST["editnumber"];
 $name=$_POST["rename"];
 $com=$_POST["recomment"];
 $date=date("Y-m-d");
 $fd= file("2_6_fordelete.kadai.txt");
 $fdd = file("2_6.kadai.txt");
 $fddd=file("2_6.kadai.public.txt");
 $data = $fd[(int)$editno-1];
 $edit = explode("<>", $data);
 $a = fopen("2_6.kadai.txt", "w");
 $b = fopen("2_6_fordelete.kadai.txt", "w");
 $c = fopen("2_6.kadai.public.txt", "w");
 $file = fopen("2_6.kadai.txt", "r");
 $array = array();
 while($line = fgets($file)){
 $nakami = explode("<>", $line);
 echo $nakami[0];
 $array[$nakami[0]] = $nakami[4];
};
print_r($array);
if(isset($id) && isset($_POST["rename"])){
	if(array_key_exists((int)$editno-1, $fdd)){
	array_splice($fdd, (int)$editno-1, 1, array(
		$editno. "<>" . $_POST["rename"]. "<>". $_POST["recomment"]. "<>". $date. $array[$editno]. "<>". "\r\n")
	);
	foreach($fdd as $value){
	fwrite($a, $value);
	};
	fclose($a);
	};
};
if(isset($_POST["recomment"]) && isset($_POST["rename"]) ){
	if(array_key_exists((int)$editno-1, $fd)){
	array_splice($fd, (int)$editno-1, 1, array(
		$_POST["rename"]. "<>". $_POST["recomment"]. "<>". $date. $array[$editno]. "<>". "\r\n"));
	foreach($fd as $value){
	fwrite($b, $value);
	};
	fclose($b);	};
}
if(isset($_POST["recomment"]) && isset($_POST["rename"]) ){
	if(array_key_exists((int)$editno-1, $fd)){
	array_splice($fd, (int)$editno-1, 1, array(
		$editno. "<>" .$_POST["rename"]. "<>". $_POST["recomment"]. "<>". $date. "\r\n"));
	foreach($fd as $value){
	fwrite($c, $value);
	};
	fclose($c);	};
}
?>
anonymous No title
PHP
//ログイン画面
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>編集確認用</title>
</head>
<body>
<form method="POST" action="2kadai_6.edit0.php" />
	<label>投稿番号</label><br/>
	<textarea readonly name="editnumber" rows="1" cols="10">
	<?php
	$pass =$_POST["input"];
$file = fopen("2_6.kadai.txt", "r");
$array = array();
while($line = fgets($file)){
$a = explode("<>", $line);
$array[$a[0]] = $a[4];
}
	echo $a[0];
	?>
</textarea>
</form>
<?php
$pass =$_POST["input"];
$file = fopen("2_6.kadai.txt", "r");
$array = array();
while($line = fgets($file)){
$a = explode("<>", $line);
$array[$a[0]] = $a[4];
}
if(in_array($pass, $array)){
header('Location: 
\\FTP情報を含むので一応隠しますが, ここについてはエラーは出ていません.
');
exit;
}else{
echo "パスワードが違います. ";
};
?>
</body>
</html>
//ログイン成功後に接続予定の画面
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>編集確認用</title>
</head>
<body>
<p><?php
 $editno=$_POST["editnum"];
 $fd= file("2_6_fordelete.kadai.txt");
 $fp= fopen("2_6_fordelete.kadai.txt", "r");
 $fpp= fopen("2_6.kadai.txt", "r");
 $data = $fd[(int)$editno-1];
 $edit = explode($data, "<>");
 if(array_key_exists((int)$editno-1, $fd)){echo "指定番号の投稿あり";}else{echo "指定番号の投稿なし";};
?></p>
<form method = "POST" action="2kadai_6.edit2.php">
	<label>投稿内容の確認</label><br />
	<input type ="hidden" name="veredit" value="true"><br />
	<label>投稿番号</label><br/>
	<textarea readonly name="editnumber" rows="1" cols="10">
	<?php
	$editno=$_POST["editnum"];
	echo $editno;
	?>
	</textarea><br/>
	<label>名前:</label><br />
	<textarea name="rename" cols="10" rows="1">
<?php
$editno=$_POST["editnum"];
$fd= file("2_6_fordelete.kadai.txt");
$fp= fopen("2_6_fordelete.kadai.txt", "r");
$fpp= fopen("2_6.kadai.txt", "r");
$data = $fd[(int)$editno-1];
$edit = explode("<>", $data);
if(array_key_exists((int)$editno-1, $fd)){
	echo $edit[0];};
?>
	</textarea><br />
	<label>コメント:</label><br />
	<textarea name="recomment" cols="50" rows="10">
<?php
$editno=$_POST["editnum"];
$fd= file("2_6_fordelete.kadai.txt");
$fp= fopen("2_6_fordelete.kadai.txt", "r");
$fpp= fopen("2_6.kadai.txt", "r");
$data = $fd[(int)$editno-1];
$edit = explode("<>", $data);
if(array_key_exists((int)$editno-1, $fd)){
	echo $edit[1];};
?>
	</textarea><br />
	<input type="submit" value="送信" /><br />
</form>
</body>
</html>
//現状だと$_POST["editnum"]に情報が遅れていないのでエラーになります.上のログイン画面からどのように情報を送ればよいのかがわからない,という質問です. 
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>
Don't you submit code?
Submit