質問編集履歴
1
初心者アイコン付加しました。ソースコードも記述させていただきます。
test
CHANGED
File without changes
|
test
CHANGED
@@ -51,3 +51,147 @@
|
|
51
51
|
|
52
52
|
|
53
53
|
よろしくお願いいたします。
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
以下のようなコードを現在書いています。
|
58
|
+
|
59
|
+
追記自体はうまくいっており、あとは投稿番号を振れればと考えています。
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
###ソースコード
|
64
|
+
|
65
|
+
<?php
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
$err_msg1 = "";
|
70
|
+
|
71
|
+
$err_msg2 = "";
|
72
|
+
|
73
|
+
$message = "";
|
74
|
+
|
75
|
+
$name = (isset($_POST["name"]) === true) ?$_POST["name"]: "";
|
76
|
+
|
77
|
+
$comment = (isset($_POST["comment"]) === true) ?trim($_POST["comment"]):"";
|
78
|
+
|
79
|
+
$date = date("Y-m-d H:i:s");
|
80
|
+
|
81
|
+
$num = 0;
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
if(isset($_POST["send"]) === true){
|
88
|
+
|
89
|
+
if($name === "") $err_msg1 = "名前を入力してください";
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
if($comment === "") $err_msg2 = "コメントを入力してください";
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
if($err_msg1 === "" && $err_msg2 === ""){
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
$file = "abc.txt";
|
102
|
+
|
103
|
+
$fp = fopen($file, "ab");
|
104
|
+
|
105
|
+
fwrite($fp, $num . '<>' . $_POST["name"] . '<>' . $_POST["comment"] . '<>' . $date. "\n");
|
106
|
+
|
107
|
+
fclose($fp);
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
$message = "書き込みに成功しました";
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
$fp_r = fopen($file,"r");
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
$dataArr= array();
|
124
|
+
|
125
|
+
while( $res = fgets($fp_r)){
|
126
|
+
|
127
|
+
$tmp = explode("<>",$res);
|
128
|
+
|
129
|
+
$arr = array(
|
130
|
+
|
131
|
+
$num => $tmp[0],
|
132
|
+
|
133
|
+
"name" => $tmp[1],
|
134
|
+
|
135
|
+
"comment" => $tmp[2],
|
136
|
+
|
137
|
+
$date => $tmp[3]
|
138
|
+
|
139
|
+
);
|
140
|
+
|
141
|
+
$dataArr[]= $arr;
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
?>
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
<!DOCTYPE html>
|
154
|
+
|
155
|
+
<html lang="ja">
|
156
|
+
|
157
|
+
<head>
|
158
|
+
|
159
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
160
|
+
|
161
|
+
<title>掲示板</title>
|
162
|
+
|
163
|
+
</head>
|
164
|
+
|
165
|
+
<body>
|
166
|
+
|
167
|
+
<?php echo $message; ?>
|
168
|
+
|
169
|
+
<form method="post" action="">
|
170
|
+
|
171
|
+
名前:<input type="text" name="name" value="<?php echo $name; ?>" >
|
172
|
+
|
173
|
+
<?php echo $err_msg1; ?><br>
|
174
|
+
|
175
|
+
コメント:<textarea name="comment" rows="4" cols="40"><?php echo $comment; ?></textarea>
|
176
|
+
|
177
|
+
<?php echo $err_msg2; ?><br>
|
178
|
+
|
179
|
+
<br>
|
180
|
+
|
181
|
+
<input type="submit" name="send" value="送信" >
|
182
|
+
|
183
|
+
</form>
|
184
|
+
|
185
|
+
<dl>
|
186
|
+
|
187
|
+
<?php foreach( $dataArr as $arr ):?>
|
188
|
+
|
189
|
+
<p><span><?php echo $count; ?></span>:<span><?php echo $arr["name"]; ?></span>:<span><?php echo $arr["comment"]; ?></span></p>
|
190
|
+
|
191
|
+
<?php endforeach;?>
|
192
|
+
|
193
|
+
</dl>
|
194
|
+
|
195
|
+
</body>
|
196
|
+
|
197
|
+
</html
|