anonymous No title
PHP
<?php
    $filename = "kadai_2-2.txt";
    if(isset($_POST["name"]) && isset($_POST["comment"])) {
      $name = $_POST["name"];
      $comment = $_POST["comment"];



      if (empty($name)) {
        $name = "名無し";
      }
      
      $fp = fopen($filename, "a");
      fwrite($fp, count(file($filename))+1);   
      fwrite($fp, "<>");
      fwrite($fp, $name."<>");
      fwrite($fp, $comment."<>");
      fwrite($fp, date("Y-m-d H:i:s")."\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>課題2-3</title>
</head>
<body>
<h1>簡易掲示板</h1>
<form action = "kadai_2-3.php" method = "post" >
    <p>名前</p>
    <input type = "text" name = "name" >
    <p>コメント</p>
    <textarea name = "comment" ></textarea><br>
    <input type = "submit" value = "投稿"><br>
  </form>

  
    <?php
      $ret_array = file($filename);
      $reverse = array_reverse($ret_array);
      
        for($i = 0; $i < count($reverse); $i++) {

          echo $reverse[$i]."<br><br>";
      }
    }
  ?>

</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-3</title>
</head>
<body>
<h1>簡易掲示板</h1>
<form action = "kadai_2-3.php" method = "post" >
    <p>名前</p>
    <input type = "text" name = "name" >
    <p>コメント</p>
    <textarea name = "comment" ></textarea><br>
    <input type = "submit" value = "投稿"><br>
  </form>

  <?php
    $filename = "kadai_2-2.txt";
    if(isset($_POST["name"]) && isset($_POST["comment"])) {
      $name = $_POST["name"];
      $comment = $_POST["comment"];



      if (empty($name)) {
        $name = "名無し";
      }
      
      $fp = fopen($filename, "a");
      fwrite($fp, count(file($filename))+1);   
      fwrite($fp, "<>");
      fwrite($fp, $name."<>");
      fwrite($fp, $comment."<>");
      fwrite($fp, date("Y-m-d H:i:s")."\n");
      fclose($fp);
      
      $ret_array = file($filename);
      $reverse = array_reverse($ret_array);
      
        for($i = 0; $i < count($reverse); $i++) {

          echo $reverse[$i]."<br><br>";
      }
    }
  ?>

</body>
</html>
anonymous No title
PHP
<html>
<head><title>課題2-6 ver. SQL</title>
<meta charset="utf-8"/>

<script type="text/javascript">
function check(){
 if(window.confirm("ほんとうに削除しますか?"))return true;
 else return false;
}
</script>
<?php
function h($str) {
    return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
}
?>

</head>
<body>
<?php
//!!環境変数になる--------------------------------------------------------------!!環境変数になる
$sqluid=XXXXXXXXXXXXXXXXX;
$sqlhost=XXXXXXXXXXXXXXXX;
$sqldbname=XXXXXXXXXXXXXX;
$sqlpswd=XXXXXXXXXXXXXXXX;
//!!環境変数になる--------------------------------------------------------------!!環境変数になる
$Ermes="";
?>

名前、コメント、パスワードを入力してください<br>
<form action="kadai2_6_sql.php" method="POST">
<?php
if(isset($_POST["editn"]) && $_POST["editn"]!=null){

try{
 $database=new PDO("mysql:host=".$sqlhost.";dbname=".$sqldbname.";charset=utf8",$sqluid,$sqlpswd);
 $sql="create table if not exists ".$sqldbname.".keiziban(num int,name nvarchar(10),comment nvarchar(1000),date datetime,status nvarchar(2),pswd nvarchar(8))";
 $database->query($sql);
 //dbがなければ生成

$sql="select name,comment from keiziban where num=".$_POST["editn"]."";
//echo($sql);
$getcomm=$database->query($sql);

foreach($getcomm as $com){
//$com=$getcomm;
//var_dump($com);
 if($com["name"]!=null) $_POST["name"]=$com["name"];
 if($com["comment"]!=null) $_POST["comment"]=$com["comment"];
 //echo' 名前  <input type="text" name="name" size="15" value="'.$comarr[1].'"><br>コメント ';
 //echo '<input type="text" name="edits" size="80" value="'.$comarr[2].'">
 echo('<input type="hidden" name="editN" size="4" value="'.$_POST['editn'].'">');
}

}catch(PDOException $e){
 echo $e->getMessage();
 die();
}
}
?>
 名前  <input type="text" name="name" size="15" value="<?php if (isset($_POST['name']) && isset($_POST['comment'])&& isset($_POST['pswd'])) if ($_POST['comment']==null  || $_POST['pswd']==null)  echo($_POST['name']) ;
if(isset($_POST["editn"]) && $_POST["editn"]!=null && isset($_POST['name']))echo($_POST['name'])  ?>">

<br>

コメント <input type="text" name="comment" size="80" value="<?php if (isset($_POST['name']) && isset($_POST['comment']) && isset($_POST['pswd'])) if($_POST['name']==null  || $_POST['pswd']==null) echo ($_POST['comment']);
if(isset($_POST["editn"]) && $_POST["editn"]!=null && isset($_POST['name']))echo($_POST['comment'])  ?>"><br>
パスワード<input type="text" name="pswd" size=8><br>
<input type="submit" value="送信"><input type="reset" value="リセット"><br>
</form>

<?php
try{
 $database=new PDO("mysql:host=".$sqlhost.";dbname=".$sqldbname.";charset=utf8",$sqluid,$sqlpswd);
$sql="create table if not exists ".$sqldbname.".keiziban(num int,name nvarchar(10),comment nvarchar(1000),date datetime,status nvarchar(2),pswd nvarchar(8))";
$database->query($sql);
//dbがなければ生成


$sql="select num from keiziban";
$getcomm=$database->query($sql);
$LineN=1;
foreach($getcomm as $R)
 if ($R["num"]+1>$LineN)$LineN=$R["num"]+1;
//echo($LineN);

if( isset($_POST["comment"])&& isset($_POST["name"]) &&  isset($_POST["pswd"])){
 if(($_POST["name"])==null)echo("名前入力に不備があります<br>");
 if( $_POST["comment"]==null)echo("コメント入力に不備があります<br>");
 if( $_POST["pswd"]==null)echo("パスワード入力に不備があります<br>");
 if( $_POST["comment"]!=null && ($_POST["name"])!=null && ($_POST["pswd"])!=null){
  if(isset($_POST["editN"])==False && isset($_POST["editn"])==False){
   $sql = "insert into keiziban (num,
                                                 name, 
                                                 comment,
                                                 date,status,
                                                 pswd
                                                 ) 
                                  values (".$LineN.",
                                           ('".$_POST["name"]."'),
                                           ('".$_POST["comment"]."'),
                                                  now(),('送信'),
                                           ('".$_POST["pswd"].
                                                 "'))";

   $statement=$database->query($sql);
   //echo($sql);echo("<br>");
   //var_dump($statement);
   echo("<br>コメント送信しました<br>");
  }
 }
}

if(isset($_POST["delete"])&& isset($_POST["pswd"])){//削除
 $sql="select pswd from keiziban where num=".$_POST["delete"];
 $R=$database->query($sql);
 foreach($R as $rqpswd){
  //var_dump($rqpswd);
  if ($_POST["pswd"]!=$rqpswd["pswd"] )$Ermes="<br>削除失敗:パスワードが一致しません<br>";
  else{
   $sql="delete from keiziban where num=".$_POST["delete"];
   $rqpswd=$database->query($sql);
  }
 }
}

if(isset($_POST["editN"])&& isset($_POST["pswd"])){
 $sql="select pswd from keiziban where num=".$_POST["editN"];
 $R=$database->query($sql);
 foreach($R as $rqpswd){
  if ($_POST["pswd"]!=$rqpswd["pswd"] )$Ermes="<br>編集失敗:パスワードが一致しません<br>";
  else{
   $sql="update keiziban set comment='".$_POST["comment"].
                                                  "',name='".$_POST["name"].
                                                    "',date=now()
                                                    ,status='編集' 
                                                     where num=".$_POST["editN"];
// echo($sql);
   $rqpswd=$database->query($sql);
  }
 }
}

//掲示板表示
$sql="select * from keiziban";
$getcomm=$database->query($sql);
if ($LineN==1)echo("コメントはまだありません<br>");
foreach($getcomm as $R){
echo h("No. ".$R["num"]." 投稿者 ".$R["name"]);
echo ("<br>");
echo (h($R["comment"]));///コメント内容
echo ("<br>");
echo (h($R["status"].//変更or更新のステータス
       "日時:".$R["date"]));
echo ("<br><br>");
}

}catch(PDOException $e){
 echo $e->getMessage();
 die();
}
echo($Ermes);
$database=null;
?>

<br><form action="kadai2_6_sql.php" method="POST" onSubmit="return check()">
削除フォーム<input type="text" name="delete" size="4"><br>
パスワード<input type="text" name="pswd" size=8><br>
<input type="submit" value="送信"><input type="reset" value="リセット">
</form>
<br><form action="kadai2_6_sql.php" method="POST">
編集フォーム<br>
編集する投稿番号<input type="number" name="editn" size="4"><br>
<input type="submit" value="送信"><input type="reset" value="リセット">
</form>
</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>課題1-7</title>
</head>
<body>
<?php
  $fileName = "kadai_1-6.txt";
  $ret_array = file($fileName);
  for($i = 0; $i < count($ret_array); ++$i) {
    echo ($ret_array[$i]."<br>");
  }
  
?>
</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>課題1-6</title>
</head>
<body>
<form action = "kadai_1-6.php" method = "post">
  <input type = "text" name = "comment"><br>
  <input type = "submit" value = "送信">
  </form>

<?php
  if(isset($_POST["comment"])) {
    $comment = $_POST["comment"];
    
    $fp = fopen("kadai_1-6.txt","a");
    fwrite($fp,$comment.PHP_EOL);
    fclose($fp);
  }
?>
</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>課題1-5</title>
</head>
<body>
<form action = "kadai_1-5.php" method = "post">
  <input type = "text" name = "comment"><br>
  <input type = "submit" value = "送信">
  </form>

<?php
  if(isset($_POST["comment"])) {
    $comment = $_POST["comment"];
    
    $fp = fopen("kadai_1-5.txt","w");
    fwrite($fp,$comment);
    fclose($fp);
  }
?>
</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>課題1ー4</title>
</head>
<body>
  <h1>課題1ー4 フォームの作成</h1>
  <form action = "kadai_1-4.php" method = "post">
  <input type = "text" name = "comment"><br>
  <input type = "submit" name = "送信">
  </form>

  <?php
    if(isset($_POST["comment"])) {
      $comment = $_POST["comment"];
      echo $comment;
    }
  ?>
  
</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>課題1ー4</title>
</head>
<body>
  <h1>課題1ー4 フォームの作成</h1>
  <form action = "kadai_1-4.php" method = "post">
  <input type = "text" name = "comment"><br>
  <input type = "submit" name = "送信">
  </form>

  <?php
    if(isset($_POST["comment"])) {
      $comment = $_POST["comment"];
      echo $comment;
    }
  ?>
  
</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>課題1-3</title>
</head>
<body>
  <?php 
    $filename = "kadai_1-2.txt";
    $fp = fopen($filename, "r");
    
    $contents = fread($fp, filesize($filename));
    var_dump($contents);

    fclose($fp);
  
  ?>
</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>課題1-2</title>
</head>
<body>
<?php
  $fp = fopen("kadai_1-2.txt","a");
  fwrite($fp,"てすと ".PHP_EOL);
  fclose($fp);
  echo "テスト"
?>
</body>
</html>
Don't you submit code?
Submit