回答編集履歴
2
ちょっとリファクタリング
answer
CHANGED
@@ -20,22 +20,41 @@
|
|
20
20
|
<!DOCTYPE html>
|
21
21
|
<html lang="ja">
|
22
22
|
<head>
|
23
|
-
|
23
|
+
<meta charset="UTF-8">
|
24
24
|
</head>
|
25
25
|
<body>
|
26
|
+
|
26
|
-
|
27
|
+
<form action="mission_1-5-2.php" method="post">
|
27
|
-
|
28
|
+
<!--入力フォームの作成-->
|
28
|
-
|
29
|
+
<input type="text" name="comment">
|
29
|
-
|
30
|
+
<input type="submit" value="送信">
|
30
|
-
|
31
|
+
</form>
|
32
|
+
|
33
|
+
|
31
|
-
|
34
|
+
<?php
|
35
|
+
|
36
|
+
// フォームから値が送信されてきているかの確認
|
37
|
+
if ( isset($_POST['comment']) === true ) {
|
38
|
+
|
39
|
+
// 送信されてきていたら、変数にその値を代入
|
32
|
-
|
40
|
+
$comment = $_POST['comment'];
|
41
|
+
|
33
|
-
|
42
|
+
// データを書き出すファイル名を設定
|
34
|
-
|
43
|
+
$filename = 'kadai5.txt';
|
44
|
+
|
45
|
+
// ファイルに書き出しを開始(ファイルハンドルの取得)
|
35
|
-
|
46
|
+
$fp = fopen($filename, 'a'); // 追加書き込みモード
|
47
|
+
|
48
|
+
// データを書きだす
|
36
|
-
|
49
|
+
fwrite($fp, $comment);
|
50
|
+
|
51
|
+
// 書き出し処理の終了(ハンドルの開放)
|
37
|
-
|
52
|
+
fclose($fp);
|
53
|
+
|
54
|
+
}
|
55
|
+
|
38
|
-
|
56
|
+
?>
|
57
|
+
|
39
58
|
</body>
|
40
59
|
</html>
|
41
60
|
```
|
1
ついき
answer
CHANGED
@@ -11,4 +11,31 @@
|
|
11
11
|
$comment=$_POST['comment'];
|
12
12
|
```
|
13
13
|
|
14
|
-
※「'(シングルクォーテーション)」の全角半角問題
|
14
|
+
※「'(シングルクォーテーション)」の全角半角問題
|
15
|
+
|
16
|
+
|
17
|
+
# 追記
|
18
|
+
|
19
|
+
```php
|
20
|
+
<!DOCTYPE html>
|
21
|
+
<html lang="ja">
|
22
|
+
<head>
|
23
|
+
<meta charset="UTF-8">
|
24
|
+
</head>
|
25
|
+
<body>
|
26
|
+
<form action="mission_1-5-2.php" method="post">
|
27
|
+
<!--入力フォームの作成-->
|
28
|
+
<input type="text" name="comment">
|
29
|
+
<input type="submit" value="送信">
|
30
|
+
</form>
|
31
|
+
<?php
|
32
|
+
$comment=$_POST['comment'];
|
33
|
+
var_dump($comment);
|
34
|
+
$filename='kadai5.txt';
|
35
|
+
$fp=fopen($filename,'w');
|
36
|
+
fwrite($fp,"$comment");
|
37
|
+
fclose($fp);
|
38
|
+
?>
|
39
|
+
</body>
|
40
|
+
</html>
|
41
|
+
```
|