anonymous No title
PHP
<h1><?php echo "登録完了";?></h1>

<?php
$dsn = "mysql:dbname=co_19_349_99sv_coco_com;host=localhost;charset=UTF8";
$name_db = "co-19-349.99sv-c";
$password_db = "U2j9s5dQ";
try {
  $mysql = new PDO($dsn,$name_db,$password_db);
} catch (PDOExcption $e){
  echo "エラー" . $e->getMessage() ;
}
$select_sql = "SELECT * FROM kadai_3_1 WHERE id=(select max(id) from kadai_3_1)";
$select_sql_query = $mysql->query($select_sql);
while ($select_sql_query_fetch = $select_sql_query->fetch(PDO::FETCH_ASSOC)) {
  echo "あなたのユーザー情報は" . "<br>" . "ID:{$select_sql_query_fetch["id"]}" . "<br>" . "名前:{$select_sql_query_fetch["name"]}" . "<br>" . "パスワード:{$select_sql_query_fetch["password"]}";
}
 ?>
anonymous No title
PHP
<?php
$dsn = "mysql:dbname=co_19_349_99sv_coco_com;host=localhost;charset=UTF8";
$name_db = "co-19-349.99sv-c";
$password_db = "U2j9s5dQ";
try {
  $mysql = new PDO($dsn,$name_db,$password_db);
} catch (PDOExcption $e){
  echo "エラー" . $e->getMessage() ;
}
if (!empty($_POST["submit"])) {
  if (!empty($_POST["password"])&&!empty($_POST["name"])) {
     if (preg_match("/^[a-zA-Z0-9]+$/",$_POST["password"])) {
        $name = $_POST["name"];
        $password = $_POST["password"];
        $insert_sql = "INSERT INTO kadai_3_1 (name, password) VALUES (?, ?)";
        $insert_sql_prepare = $mysql->prepare($insert_sql);
        $insert_sql_execute = $insert_sql_prepare->execute(array($name, $password));
        header('Location: kadai_3_1_entry.php');
     }else{
       echo "パスワードは半角英数字で入力してください";
     }
  }else{
    echo "パスワードと名前を両方入力してください";
  }
}
?>
<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <title>登録フォーム</title>
  </head>
  <body>
    <h1>新規登録</h1>
    <p>*名前とパスワードを半角で入力してください</p>
    <br />
    <form action="kadai_3_1.php" method="post">
      名前:<input type="text" name="name"><br>
      <br />
      パスワード:<input type="text" name="password"><br>
      <br />
      <input type="submit" name="submit" 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>簡易掲示板</title>
</head>

<body>

    <h2>入力フォーム</h2>
    <form action="" method="POST">
        <input type="hidden" name="editnumber" size='20' value='' placeholder="名前"><br />
        <input type="text" name="name" size='20' value='' placeholder="名前"><br />
        <input type="text" name="comment" size='20' value='' placeholder="コメント"><br />
        <input type="password" name="password" size='20' value='' placeholder="パスワード"><br />
        <br />
        <input type="submit" name='submit' value='送信' />
    </form>

    <form action="" method="POST">
        <h2>削除フォーム</h2>
        <input type="number" name="deletenumber" size='20' placeholder="削除番号"><br />
        <input type="password" name="deletepassword" placeholder="パスワード"><br />
        <br />
        <input type="submit" name='delete' value='削除' onclick="return confirm('削除しますか?')" />
        <br />
        <br />
    </form>

    <form action="" method="POST">
        <h2>編集フォーム</h2>
        <input type="text" name="editnumber" placeholder="編集番号"><br />
        <input type="password" name="editpassword" placeholder="パスワード"><br />
        <br />
        <input type="submit" name="edit" value="編集"><br />
        <br />
        <br />
    </form>


    <?php
    // データベースへ接続
    try {
        $dsn = 'mysql:dbname=co_19_349_99sv_coco_com;host=localhost';
        $user = 'co-19-349.99sv-c';
        $password = 'U2j9s5dQ';
        $pdo = new PDO($dsn, $user, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
    } catch (PDOException $e) {
        echo 'DB接続エラー' . $e->getMessage;
    }


    // リセット用
    // $sql = "DROP TABLE kadai2a";
    // $pdo->query($sql);


    // テーブルを作成
    $sql = "CREATE TABLE IF NOT EXISTS kadai2a"
        . "("
        . "id INT AUTO_INCREMENT PRIMARY KEY,"
        . "name char(32),"
        . "comment TEXT,"
        . "date DATETIME,"
        . "password TEXT"
        . ");";
    $stmt = $pdo->query($sql);


    // 新規投稿
    if (isset($_POST['submit'])) {
        if (isset($_POST['name']) && (isset($_POST['comment'])) && (isset($_POST['password']))) {
            $sql = $pdo->prepare("INSERT INTO kadai2a (name,comment,date,password) VALUES (:name,:comment,:date,:password)");
            $sql->bindParam(':name', $name, PDO::PARAM_STR);
            $sql->bindParam(':comment', $comment, PDO::PARAM_STR);
            $sql->bindParam(':date', $date, PDO::PARAM_STR);
            $sql->bindParam(':password', $password, PDO::PARAM_STR);
            $name = $_POST['name'];
            $comment = $_POST['comment'];
            date_default_timezone_set('Asia/Tokyo');
            $date = date("Y/m/d H:i:s");
            $password = $_POST['password'];
            $sql->execute();
        }
        if ((empty($name)) || (empty($comment)) || (empty($password))) {
            echo "<script>alert('未入力項目があります')</script>";
        }
    }

    // 編集
    if (isset($_POST['edit'])) {
        if ((isset($_POST['editnumber'])) && (isset($_POST['editpassword']))) {
            $editnumber = $_POST['editnumber'];
            $editpassword = $_POST['editpassword'];
            $results = $pdo->query("SELECT * FROM kadai2a WHERE id= $editnumber");
            foreach ($results as $result) {
                if ($editnumber == $result['id'] && $editpassword == $result['password']) {
                    $editnumber = $result['id'];
                    $editname = $result['name'];
                    $editcomment = $result['comment'];
                    $editpassword = $result['password'];
                    echo "編集番号" . $editnumber
    ?>
                    <form action="<?php echo ($_SERVER['PHP_SELF']) ?>" method="POST">
                        <input type="hidden" name="editnumber" value="<?php if (isset($editnumber)) {
                                                                            echo $editnumber;
                                                                        } ?>">
                        <h3>名前:</h3>
                        <input type="text" name="editname" value="<?php if (isset($editname)) {
                                                                        echo $editname;
                                                                    } ?>">
                        <h3>コメント:</h3>
                        <input type="text" name="editcomment" value="<?php if (isset($editcomment)) {
                                                                            echo $editcomment;
                                                                        } ?>">
                        <h3>パスワード:</h3>
                        <input type="password" name="editpassword" value="<?php if (isset($editpassword)) {
                                                                                echo $editpassword;
                                                                            } ?>"><br />
                                                                            <br />
                        <input type="submit" name="editsubmit" value="編集"><br /><br /><br />
                    </form>
    <?php
                    break;
                } elseif ($editnumber == $result['id'] && $editpassword != $result['password']) {
                    echo "<script>alert('パスワードが違います')</script>";
                }
            }
        }
    }
    if (isset($_POST['editsubmit'])) {
        if (!empty($_POST["editname"]) && (!empty($_POST["editcomment"])) && (!empty($_POST["editpassword"]))) {
            try {
                $dsn = 'mysql:dbname=co_19_349_99sv_coco_com;host=localhost';
                $user = 'co-19-349.99sv-c';
                $password = 'U2j9s5dQ';
                $pdo = new PDO($dsn, $user, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
                $editnumber = $_POST['editnumber'];
                $name = $_POST['editname'];
                $comment = $_POST['editcomment'];
                date_default_timezone_set('Asia/Tokyo');
                $date = date("Y/m/d H:i:s");
                $password = $_POST['editpassword'];
                $sql = "UPDATE kadai2a SET name=:name,comment=:comment,date=:date,password=:password WHERE id=$editnumber";
                $stmt = $pdo->prepare($sql);
                $stmt->execute(array(':name' => $name, ':comment' => $comment, ':date' => $date, ':password' => $password));
            } catch (PDOException $e) {
                echo 'DB接続エラー' . $e->getMessage;
            }
        }
    }


    // 削除
    if (isset($_POST['delete'])) {
        if ((isset($_POST['delete'])) && (isset($_POST['deletepassword']))) {
            $deletenumber = $_POST['deletenumber'];
            $deletepassword = $_POST['deletepassword'];
            $res = $pdo->query('SELECT * FROM kadai2a');
            foreach ($res as $value) {
                if ($deletenumber == $value['id'] && $deletepassword == $value['password']) {
                    $id = $deletenumber;
                    $sql = 'delete from kadai2a where id=:id';
                    $stmt = $pdo->prepare($sql);
                    $stmt->bindParam(':id', $id, PDO::PARAM_INT);
                    $stmt->execute();
                } elseif ($deletenumber == $value['id'] && $deletepassword != $value['password']) {
                    echo "<script>alert('パスワードが違います')</script>";
                }
            }
        }
    }




    // データを表示する
    $sql = 'SELECT * FROM kadai2a';
    $stmt = $pdo->prepare($sql);
    $stmt->execute();
    $results = $stmt->fetchAll();
    foreach ($results as $row) {
        echo $row['id'] . ',';
        echo $row['name'] . ',';
        echo $row['comment'] . ',';
        echo $row['date'] . '<br>';
        echo "<hr>";
    }
    ?>

</body>

</html>
anonymous No title
PHP
<?php
 echo "Hello World";
?>
anonymous No title
PHP
<!DOCTYPE html>
<html lang="ja" >
  <head>
    <meta charset="utf-8">
    <title>簡易掲示板</title>
  </head>

  <body>
    <h1>簡易掲示板</h1>
    <form action="" method="post">
      
      <p>名前</p>
      <input type="text" name="user_name"><br>
      
      <p>コメント</p>
      <textarea name="comment" rows="4" cols="40"></textarea><br>
     
      <input type="submit" value="送信">
    </form>
<?php

error_reporting(0);
  
    $name=$_POST["user_name"];
   
   $comment=$_POST["comment"];
   
   $date=date("Y-m-d H:i:s");
  
   $filename="kadai_2_3(3).txt";
   
   $num=count(file($filename))+1;
   
   $parts="$num<>$name<>$comment<>$date";
  
   $fp=fopen($filename,"a");

    if(empty($name) && empty($comment)){
       echo "未記入箇所があります。<br>";
   }
  
   elseif(empty($name) ){
       echo "名前を入力してください<br>";
   }
  
   elseif(empty($comment)){
       echo "コメントを入力してください<br>";
   }
   
   elseif(isset($name) && isset($comment)){
     fwrite($fp,"$parts".PHP_EOL);
     fclose($fp);
   }
  
   if(file_exists($filename)){
     
     $lines=file($filename,FILE_IGNORE_NEW_LINES);
     foreach($lines as $line){
      
       list($num,$name,$comment,$date)=explode("<>",$line);
      
       echo "$num<>$name<>$comment<>$date"."<br>";
     }
   }
?>
  </body>
</html>
anonymous No title
PHP
<?php

define( 'FILENAME', 'kadai_2_3(2).txt');

date_default_timezone_set('Asia/Tokyo');

$now_date = null;
$data = null;
$file_handle = null;
$split_data = null;
$message = array();
$message_array = array();


if( !empty($_POST['btn_submit']) ) {
	
	if( $file_handle = fopen( FILENAME, "a") ) {
		$now_date = date("Y-m-d H:i:s");
		if (file_exists($filename)) {
   		 $num = count(file($filename))+1;
		} else {
    			$num = 1;
		}
		$data = $num."<>".$_POST['view_name']."<>".$_POST['message']."<>".$now_date.;

	
		fwrite( $file_handle, $data);
	
		fclose( $file_handle);
	}		
}

if( $file_handle = fopen( FILENAME,'r') ) {
	while( $data = fgets($file_handle) ){
	
		$split_data = preg_split( '/\'/', $data);
		
		$message = array(
			'view_name' => $split_data[1],
			'message' => $split_data[3],
			'post_date' => $split_data[5]
		);
		array_unshift( $message_array, $message);
	}
	
	fclose( $file_handle);
}

?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>簡易掲示板</title>
</head>
<body>
<h1>簡易掲示板</h1>
<form method="post">
	<div>
		<label for="view_name">名前</label>
		<input id="view_name" type="text" name="view_name" value="">
	</div>
	<div>
		<label for="message">コメント</label>
		<textarea id="message" name="message"></textarea>
	</div>
	<input type="submit" name="btn_submit" value="送信">
</form>
<hr>
<section>
<?php if( !empty($message_array) ): ?>
<?php foreach( $message_array as $value ): ?>
<article>
    <div class="info">
        <h2><?php echo $value['view_name']; ?></h2>
        <time><?php echo date('Y年m月d日 H:i', strtotime($value['post_date'])); ?></time>
    </div>
    <p><?php echo $value['message']; ?></p>
</article>
<?php endforeach; ?>
<?php endif; ?>
</section>
</body>
</html>
anonymous No title
PHP
<?php
define( 'FILENAME', 'kadai_2_3(2).txt');
date_default_timezone_set('Asia/Tokyo');
$now_date = null;
$data = null;
$file_handle = null;
$split_data = null;
$message = array();
$message_array = array();

if( !empty($_POST['btn_submit']) ) {
	if( $file_handle = fopen( FILENAME, "a") ) {
		$now_date = date("Y-m-d H:i:s");
  		$num=count(file($filename));
		$num++;
		$data = $num."<>".$_POST['view_name']."<>".$_POST['message']."<>".$now_date."'\n";
		fwrite( $file_handle, $data);
		fclose( $file_handle);	
	}	
}

if( $file_handle = fopen( FILENAME,'r') ) {
	while( $data = fgets($file_handle) ){
		$split_data = preg_split( '/\'/', $data);
        	$message = array(
            	'view_name' => $split_data[1],
            	'message' => $split_data[3],
            	'post_date' => $split_data[5]
        	);
        	array_unshift( $message_array, $message);
    }
	fclose( $file_handle);

?>


<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>簡易掲示板</title>
</head>
<body>
<h1>簡易掲示板</h1>
<form method="post">
	<div>
		<label for="view_name">名前</label>
		<input id="view_name" type="text" name="view_name" value="">
	</div>
	<div>
		<label for="message">コメント</label>
		<textarea id="message" name="message"></textarea>
	</div>
	<input type="submit" name="btn_submit" value="送信">
</form>
<hr>
<section>
<?php if( !empty($message_array) ): ?>
<?php foreach( $message_array as $value ): ?>
<article>
    <div class="info">
        <h2><?php echo $value['view_name']; ?></h2>
        <time><?php echo date('Y年m月d日 H:i', strtotime($value['post_date'])); ?></time>
    </div>
    <p><?php echo $value['message']; ?></p>
</article>
<?php endforeach; ?>
<?php endif; ?>
</section>
</body>
</html>
anonymous No title
PHP
<?php
define( 'FILENAME', 'kadai_2_3(2).txt');
date_default_timezone_set('Asia/Tokyo');
$now_date = null;
$data = null;
$file_handle = null;
$split_data = null;
$message = array();
$message_array = array();

if( !empty($_POST['btn_submit']) ) {
	if( $file_handle = fopen( FILENAME, "a") ) {
		$now_date = date("Y-m-d H:i:s");
  		$num=count(file($filename));
		$num++;
		$data = $num."<>".$_POST['view_name']."<>".$_POST['message']."<>".$now_date."'\n";
		fwrite( $file_handle, $data);
		fclose( $file_handle);	
	}	
}

if( $file_handle = fopen( FILENAME,'r') ) {
	while( $data = fgets($file_handle) ){
		$split_data = preg_split( '/\'/', $data);
        	$message = array(
            	'view_name' => $split_data[1],
            	'message' => $split_data[3],
            	'post_date' => $split_data[5]
        	);
        	array_unshift( $message_array, $message);
    }
	fclose( $file_handle);
}
?>


<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>簡易掲示板</title>
</head>
<body>
<h1>簡易掲示板</h1>
<form method="post">
	<div>
		<label for="view_name">名前</label>
		<input id="view_name" type="text" name="view_name" value="">
	</div>
	<div>
		<label for="message">コメント</label>
		<textarea id="message" name="message"></textarea>
	</div>
	<input type="submit" name="btn_submit" value="送信">
</form>
<hr>
<section>
<?php if( !empty($message_array) ): ?>
<?php foreach( $message_array as $value ): ?>
<article>
    <div class="info">
        <h2><?php echo $value['view_name']; ?></h2>
        <time><?php echo date('Y年m月d日 H:i', strtotime($value['post_date'])); ?></time>
    </div>
    <p><?php echo $value['message']; ?></p>
</article>
<?php endforeach; ?>
<?php endif; ?>
</section>
</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html>
<head>
<title>kadai_4 php</title>
</head>
<body>
<form action = "kadai_4.php" mothod = "get">
	<input type = "text" name ="sendtext"><br/>
	<input type ="submit" valude ="送信">
</form>
<?php
	echo "入力されたテキストが下に表示されます<br/>";
	if(isset($_GET["sendtext"])){
		echo $_GET["sendtext"];
	}
?>
</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html>
<head>
<title>kadai_3 php</title>
</head>
<body>
<?php
echo file_get_contents("saveDoc.txt");
?>
</body>
</html>
Don't you submit code?
Submit