anonymous No title
PHP
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
</head>
<body>
<h3>内容を編集してください</h3><hr>
<?php
	$file = "kadai_2-6.text";
	$comments = file($file);
	
	foreach ($comments as $text) {
		$texts = explode("<>", $text);
		if ($_POST['edit'] == $texts[0] and $_POST['edit_pass'] == $texts[4]) {
			$number = $texts[0];
			$name = $texts[1];
			$comment = $texts[2];
			$pass = $texts[4];
		}
	}
	
	if (empty($number)) {
		echo "パスワードが違います";
	}
?>

<form action="kadai_2-6_edit-confirm.php" method="post">
	<input type="hidden" name="number" value="<?php if (!empty($number)) {echo $number;} ?>">
	<input type="text" name="name" value="<?php if (!empty($name)) {echo $name;} ?>"><br>
	<input type="text" name="comment" value="<?php if (!empty($comment)) {echo $comment;} ?>"><br>
	<input type="hidden" name="pass" value="<?php if (!empty($pass)) {echo $pass;} ?>"><br>
	<input type="submit" value="確認">
</form>
</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
</head>
<body>
<form action="kadai_2-6_edit-number.php" method="post">
	編集対象番号:<input type="text" name="edit" placeholder="編集対象番号"><br>
	パスワード:<input type="text" name="edit_pass" placeholder="パスワード">
	<input type="submit" value="送信">
</form>
</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
</head>
<body>
<h3>本当にこの投稿を削除しますか?</h3><hr>
<?php
	$file = "kadai_2-6.text";
	$comments = file($file);
	$number = "";
	if (!empty($_POST['delete']) and !empty($_POST['delete_pass'])) {
		foreach ($comments as $text) {
			$texts = explode("<>", $text);
			if ($_POST['delete'] == $texts[0] and $_POST['delete_pass'] == $texts[4]) {
				$number = $texts[0];
				$name = $texts[1];
				$comment = $texts[2];
				$time = $texts[3];
				echo $texts[0]. " ". $texts[1]. "<br>". $texts[2]. "<br>". $texts[3]. "<hr>";
			}
		}
	}
	
	if (empty($number)) {
		echo "パスワードが違います";
	}
?>
<form action="kadai_2-6_home.php" method="post">
	<input type="hidden" name="delete" value="<?php if (!empty($_POST['delete'])) { echo $_POST['delete']; } ?>">
	<input type="hidden" name="delete_pass" value="<?php if (!empty($_POST['delete_pass'])) { echo $_POST['delete_pass']; } ?>">
	<input type="submit" value="削除">
</form>
</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
</head>
<body>
<form action="kadai_2-6.delete-confirm.php" method="post">
	削除対象番号:<input type="text" name="delete" placeholder="削除対象番号"><br>
	パスワード:<input type="text" name="delete_pass" placeholder="パスワード">
	<input type="submit" value="確認">
</form>
</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
</head>
<body>
<h3>入力内容の確認</h3>
<form action="kadai_2-6_home.php" method="post">
	名前:<input type="text" name="name" value="<?php if(!empty($_POST['name'])){ echo $_POST['name'];} ?>" placeholder="お名前が未入力です"><br>
	コメント:<input type="text" name="comment" value="<?php if(!empty($_POST['comment'])){ echo $_POST['comment'];} ?>" placeholder="コメントが未入力です"><br>
	パスワード:<input type="text" name="pass" value="<?php if(!empty($_POST['password'])) { echo $_POST['password'];} ?>" placeholder="パスワードが未入力です">
	<input type="submit" value="投稿">
</form>
<form action="kadai_2-6_post.php" method="post">
	<input type="submit" value="戻る">
</form>
</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
</head>
<body>
<form action="kadai_2-6_post-confirm.php" method="post">
	名前:<input type="text" name="name" placeholder="名前"><br>
	コメント:<input type="text" name="comment" placeholder="コメント"><br>
	パスワード:<input type="text" name="password" placeholder="パスワード">
	<input type="submit" value="内容の確認">
</form>
</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
</head>
<body>
	<?php
		$file = "kadai_2-6.text";
		$comments = file($file);
		$num = count($comments) + 1;
		$now = date("Y年m月d日 H時i分s秒");
		
		if (!empty($_POST['name']) and !empty($_POST['comment']) and !empty($_POST['pass'])){
			$fp = fopen($file, "a");
			fwrite($fp, $num. "<>". $_POST['name']. "<>". $_POST['comment']. "<>". $now. "<>". $_POST['pass']. "<>". "\n");
			fclose($fp);
		}
		
		if (!empty($_POST['delete']) and !empty($_POST['delete_pass'])) {
			$fp = fopen($file, "w");
			foreach ($comments as $text) {
				$texts = explode("<>", $text);
				if ($_POST['delete'] !== $texts[0]) {
					fwrite($fp, $text);
				} elseif ($_POST['delete_pass'] !== $texts[4]){
					fwrite($fp, $text);
				}
			}
			fclose($fp);
		}
		
		if (!empty($_POST['edit-num']) and !empty($_POST['edit-name']) and !empty($_POST['edit-comment']) and !empty($_POST['edit-pass'])) {
			$fp = fopen($file, "w");
			foreach($comments as $text) {
				$texts = explode("<>", $text);
				if ($texts[0] == $_POST['edit-num'] and $texts[4] == $_POST['edit-pass']) {
					fwrite($fp, $texts[0]. "<>". $_POST['edit-name']. "<>". $_POST['edit-comment']. "<>". $now. "<>". $_POST['edit-pass']. "<>". "\n");
				} else {
					fwrite($fp, $text);
				}
			}
			fclose($fp);
		}
	?>
	<h3>投稿一覧<h3>
	<form action="kadai_2-6_post.php" method="post">
		<input type="submit" value="新規投稿">
	</form>
	<form action="kadai_2-6_delete.php" method="post">
		<input type="submit" value="削除">
	</form>
	<form action="kadai_2-6_edit.php" method="post">
		<input type="submit" value="編集">
	</form>
	<hr>
	<?php
		$file = "kadai_2-6.text";
		$comments = file($file);
		foreach($comments as $text) {
			$texts = explode("<>", $text);
			echo $texts[0]. " ". $texts[1]. "<br>". $texts[2]. "<br>". $texts[3]. "<hr>";
		}
	?>
</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html>
	<head>
		
		<meta charset="UTF-8">
		
	</head>
	<body>
		<?php
			$file = "kadai_13.text";
			$comments = file($file);
			$num = count($comments) + 1;//count()関数は()内の配列変数の要素の数を数える
			$now = date("Y年m月d日 H時i分s秒");
			
			if (!empty($_POST['number']) and !empty($_POST['name']) and !empty($_POST['comment']) and !empty($_POST['pass'])) {
				$fp = fopen($file, "w");
				foreach ($comments as $text) {
					$texts = explode("<>", $text);
					if ($texts[0] == $_POST['number'] and $texts[4] == $_POST['pass']) {
						fwrite($fp, $texts[0]. "<>". $_POST['name']. "<>". $_POST['comment']. "<>". $now. "<>". $texts[4]. "<>". "\n");
					} else {
						fwrite($fp, $text);
					}
				}
				fclose($fp);
			} elseif (!empty($_POST['name']) and !empty($_POST['comment']) and !empty($_POST['pass'])) {
				$fp = fopen($file, "a");
				fwrite($fp, $num. "<>". $_POST['name']. "<>". $_POST['comment']. "<>". $now. "<>". $_POST['pass']. "<>". "\n");
				fclose($fp);
			}
						
			if (!empty($_POST['delete']) and !empty($_POST['delete_pass'])) {
				$fp = fopen($file, "w");
				foreach ($comments as $text) {
					$texts = explode("<>", $text);
					if ($_POST['delete'] !== $texts[0]) {
						fwrite($fp, $text);
					} elseif ($_POST['delete_pass'] !== $texts[4]){
						fwrite($fp, $text);
					}
				}
				fclose($fp);
			}
			
			if (!empty($_POST['edit']) and !empty($_POST['edit_pass'])) {
				foreach ($comments as $text){
					$texts = explode("<>", $text);
					if ($_POST['edit'] == $texts[0] and $_POST['edit_pass'] == $texts[4]) {
						$number = $texts[0];
						$name = $texts[1];
						$comment = $texts[2];
						$pass = $texts[4];
					}
				}
			}	
			//HTML領域でphpの変数を使うときはvalue=""の中にphp領域を作る	
		?>
		<form action="kadai_13.php" method="post">
			名前:<input type="text" name="name" value="<?php  if (!empty($name)){ echo $name; } ?>" placeholder="名前"><br>
			コメント:<input type="text" name="comment" value="<?php  if (!empty($comment)){ echo $comment; } ?>" placeholder="コメント"><br>
			パスワード:<input type="text" name="pass" value="<?php  if (!empty($pass)){ echo $pass; } ?>" placeholder="パスワード"><br>
			<input type="hidden" name="number" value="<?php  if (!empty($number)){ echo $number; } ?>">
			<input type="submit" value="送信"><br><br>
			削除対象番号:<input type="text" name="delete" placeholder="削除対象番号"><br>
			パスワード:<input type="text" name="delete_pass" placeholder="パスワード">
			<input type="submit" value="削除"><br>
			編集対象番号:<input type="text" name="edit" placeholder="編集対象番号"><br>
			<input type="text" name="edit_pass" placeholder="パスワード">
			<input type="submit" value="編集">
		</form>
		
		<?php
			$comments = file($file);
			foreach ($comments as $text) {
				$texts = explode("<>", $text);
				echo $texts[0]. " ". $texts[1]. " ". $texts[2]. " ". $texts[3]. "<br>";
			}
		?>
	</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html>
	<head>
		
		<meta charset="UTF-8">
		
	</head>
	<body>
		<?php
			$file = "kadai_12.text";
			$comments = file($file);
			$num = count($comments) + 1;//count()関数は()内の配列変数の要素の数を数える
			$now = date("Y年m月d日 H時i分s秒");
			
			if (!empty($_POST['number']) and !empty($_POST['name']) and !empty($_POST['comment'])) {
				$fp = fopen($file, "w");
				foreach ($comments as $text) {
					$texts = explode("<>", $text);
					if ($texts[0] == $_POST['number']) {
						fwrite($fp, $texts[0]. "<>". $_POST['name']. "<>". $_POST['comment']. "<>". $now. "<>". "\n");
					} else {
						fwrite($fp, $text);
					}
				}
				fclose($fp);
			} elseif (!empty($_POST['name']) and !empty($_POST['comment'])) {
				$fp = fopen($file, "a");
				fwrite($fp, $num. "<>". $_POST['name']. "<>". $_POST['comment']. "<>". $now. "<>". "\n");
				fclose($fp);
			}
						
			if (!empty($_POST['delete'])) {
				$fp = fopen($file, "w");
				foreach ($comments as $text) {
					$texts = explode("<>", $text);
					if ($_POST['delete'] !== $text[0]) {
						fwrite($fp, $text);
					}
				}
				fclose($fp);
			}
			
			if (!empty($_POST['edit'])) {
				foreach ($comments as $text){
					$texts = explode("<>", $text);
					if ($_POST['edit'] == $texts[0]) {
						$number = $texts[0];
						$name = $texts[1];
						$comment = $texts[2];
					}
				}
			}	
			//HTML領域でphpの変数を使うときはvalue=""の中にphp領域を作る	
		?>
		<form action="kadai_12.php" method="post">
			名前:<input type="text" name="name" value="<?php  if (!empty($name)){ echo $name; } ?>" placeholder="名前"><br>
			コメント:<input type="text" name="comment" value="<?php  if (!empty($comment)){ echo $comment; } ?>" placeholder="コメント"><br>
			<input type="hidden" name="number" value="<?php  if (!empty($number)){ echo $number; } ?>">
			<input type="submit" value="送信"><br><br>
			削除対象番号:<input type="text" name="delete" placeholder="削除対象番号">
			<input type="submit" value="削除"><br>
			編集対象番号:<input type="text" name="edit" placeholder="編集対象番号">
			<input type="submit" value="編集">
		</form>
		
		<?php
			$comments = file($file);
			foreach ($comments as $text) {
				$texts = explode("<>", $text);
				echo $texts[0]. " ". $texts[1]. " ". $texts[2]. " ". $texts[3]. "<br>";
			}
		?>
	</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html>
	<head>
		
		<meta charset="UTF-8">
		
	</head>
	<body>
		<form action="kadai_11.php" method="post">
			名前:<input type="text" name="name" placeholder="名前"><br>
			コメント:<input type="text" name="comment" placeholder="コメント"><br>
			<input type="submit" value="送信"><br><br>
			削除対象番号:<input type="text" name="delete" placeholder="削除対象番号">
			<input type="submit" value="削除">
		</form>
		
		<?php
			$file = "kadai_11.text";
			$comments = file($file);
			$num = count($comments) + 1;//count()関数は()内の配列変数の要素の数を数える
			$now = date("Y年m月d日 H時i分s秒");
			
			if (!empty($_POST['name']) and !empty($_POST['comment'])) {
				$fp = fopen($file, "a");
				fwrite($fp, $num. "<>". $_POST['name']. "<>". $_POST['comment']. "<>". $now. "<>". "\n");
				fclose($fp);
			}
			
			if (!empty($_POST['delete'])) {
				$fp = fopen($file, "w");
				foreach ($comments as $text) {
					$texts = explode("<>", $text);
					if ($_POST['delete'] !== $text[0]) {
						fwrite($fp, $text);
					}
				}
				fclose($fp);
			}
			
			$comments = file($file);
			foreach ($comments as $text) {
				$texts = explode("<>", $text);
				echo $texts[0]. " ". $texts[1]. " ". $texts[2]. " ". $texts[3]. "<br>";
			}
		?>
	</body>
</html>
Don't you submit code?
Submit