質問編集履歴
2
誤字修正2
test
CHANGED
File without changes
|
test
CHANGED
@@ -196,9 +196,9 @@
|
|
196
196
|
|
197
197
|
//変数に代入
|
198
198
|
|
199
|
-
$filename='
|
199
|
+
$filename='2-5.txt';
|
200
|
-
|
200
|
+
|
201
|
-
$passfile='
|
201
|
+
$passfile='2-5_pass.txt';
|
202
202
|
|
203
203
|
|
204
204
|
|
1
誤字修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,45 +26,439 @@
|
|
26
26
|
|
27
27
|
<?php
|
28
28
|
|
29
|
+
$filename='2-5.txt';
|
30
|
+
|
31
|
+
$passfile='2-5_pass.txt';
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
//編集選択
|
36
|
+
|
37
|
+
if(!empty($_POST["password3"])) {
|
38
|
+
|
39
|
+
$password3=$_POST["password3"];
|
40
|
+
|
41
|
+
$pass3=file($passfile);
|
42
|
+
|
43
|
+
foreach($pass3 as $word3) {
|
44
|
+
|
45
|
+
$PASS3=explode('<>', trim($word3));
|
46
|
+
|
47
|
+
$id=$PASS3[1];
|
48
|
+
|
49
|
+
if( ($id==$password3)&&(!empty($_POST["editing"])) ) {
|
50
|
+
|
51
|
+
$editing=$_POST["editing"];
|
52
|
+
|
53
|
+
$editors=file($filename);
|
54
|
+
|
55
|
+
foreach($editors as $editor) {
|
56
|
+
|
57
|
+
$EDITOR=explode('<>', $editor);
|
58
|
+
|
59
|
+
$id=$EDITOR[0];
|
60
|
+
|
61
|
+
if($id==$editing) {
|
62
|
+
|
63
|
+
$ID=current(array_slice($EDITOR, 0, 1));
|
64
|
+
|
65
|
+
$NAME=current(array_slice($EDITOR, 1, 1));
|
66
|
+
|
67
|
+
$COMMENT=current(array_slice($EDITOR, 2, 1));
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
//編集実行
|
82
|
+
|
83
|
+
if( (!empty($_POST["edit"]))&&(empty($_POST["password1"])) ) {
|
84
|
+
|
85
|
+
$edit=$_POST["edit"];
|
86
|
+
|
87
|
+
$Editors=file($filename);
|
88
|
+
|
89
|
+
$fp=fopen($filename, 'w');
|
90
|
+
|
91
|
+
foreach($Editors as $Editor) {
|
92
|
+
|
93
|
+
$EDIT=explode('<>', $Editor);
|
94
|
+
|
95
|
+
$NO=current(array_slice($EDIT, 0, 1));
|
96
|
+
|
97
|
+
if($NO==$edit) {
|
98
|
+
|
99
|
+
$name=$_POST["name"];
|
100
|
+
|
101
|
+
$comment=$_POST["comment"];
|
102
|
+
|
103
|
+
$date=date('Y/m/d H:i');
|
104
|
+
|
105
|
+
fwrite($fp, $edit.'<>'.$name.'<>'.$comment.'<>'.$date."\n");
|
106
|
+
|
107
|
+
} else {
|
108
|
+
|
109
|
+
fwrite($fp, $Editor);
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
fclose($fp);
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
?>
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
<!DOCTYPE html>
|
124
|
+
|
125
|
+
<html lang="ja">
|
126
|
+
|
127
|
+
<head>
|
128
|
+
|
129
|
+
<meta charset="UTF-8" />
|
130
|
+
|
131
|
+
<title>H2O</title>
|
132
|
+
|
133
|
+
</head>
|
134
|
+
|
135
|
+
<body>
|
136
|
+
|
137
|
+
<form method="POST" action=" ">
|
138
|
+
|
139
|
+
<p>
|
140
|
+
|
141
|
+
<!--投稿-->
|
142
|
+
|
143
|
+
<input type="text" name="name" placeholder="名前" value="<?php echo $NAME ?>"> <br />
|
144
|
+
|
145
|
+
<input type="text" name="comment" placeholder="コメント" value="<?php echo $COMMENT ?>"> <br />
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
<!--編集実行-->
|
150
|
+
|
151
|
+
<input type="hidden" name="edit" value="<?php echo $ID ?>"> <br />
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
<!--パスワード欄-->
|
156
|
+
|
157
|
+
<input type="text" name="password1" placeholder="パスワード">
|
158
|
+
|
159
|
+
<input type="submit" value="送信"> <br />
|
160
|
+
|
161
|
+
<br />
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
<!--削除-->
|
166
|
+
|
167
|
+
<input type="text" name="delete" placeholder="削除対象番号"> <br />
|
168
|
+
|
169
|
+
<input type="text" name="password2" placeholder="パスワード">
|
170
|
+
|
171
|
+
<input type="submit" value="削除"> <br />
|
172
|
+
|
173
|
+
<br />
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
<!--編集選択-->
|
178
|
+
|
179
|
+
<input type="text" name="editing" placeholder="編集対象番号"> <br />
|
180
|
+
|
181
|
+
<input type="text" name="password3" placeholder="パスワード">
|
182
|
+
|
183
|
+
<input type="submit" value="編集"> <br />
|
184
|
+
|
185
|
+
</p>
|
186
|
+
|
187
|
+
</form>
|
188
|
+
|
189
|
+
</body>
|
190
|
+
|
191
|
+
</html>
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
<?php
|
196
|
+
|
197
|
+
//変数に代入
|
198
|
+
|
29
199
|
$filename='mission_2-5_ver2.txt';
|
30
200
|
|
31
201
|
$passfile='mission_2-5_pass_ver2.txt';
|
32
202
|
|
33
203
|
|
34
204
|
|
205
|
+
//新規投稿
|
206
|
+
|
207
|
+
if( (!empty($_POST["name"])&&($_POST["comment"])&&($_POST["password1"])) && (empty($_POST["edit"])) ) {
|
208
|
+
|
209
|
+
if(empty($filename)) {
|
210
|
+
|
211
|
+
$name=$_POST["name"];
|
212
|
+
|
213
|
+
$comment=$_POST["comment"];
|
214
|
+
|
215
|
+
$number=count(file($filename));
|
216
|
+
|
217
|
+
$num=$number++;
|
218
|
+
|
219
|
+
$date=date('Y/m/d H:i');
|
220
|
+
|
221
|
+
$post=$num.'<>'.$name.'<>'.$comment.'<>'.$date."\n";
|
222
|
+
|
223
|
+
file_put_contents($filename, $post, FILE_APPEND);
|
224
|
+
|
225
|
+
$password1=$_POST["password1"];
|
226
|
+
|
227
|
+
file_put_contents($passfile, $num.'<>'.$password1."\n", FILE_APPEND);
|
228
|
+
|
229
|
+
} else {
|
230
|
+
|
231
|
+
$name=$_POST["name"];
|
232
|
+
|
233
|
+
$comment=$_POST["comment"];
|
234
|
+
|
235
|
+
$date=date('Y/m/d H:i');
|
236
|
+
|
237
|
+
$lines=file($filename);
|
238
|
+
|
239
|
+
$number=0;
|
240
|
+
|
241
|
+
foreach($lines as $line) {
|
242
|
+
|
243
|
+
$array=explode('<>', $line);
|
244
|
+
|
245
|
+
$id=$array[0];
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
$num=$id+1;
|
250
|
+
|
251
|
+
$post=$num.'<>'.$name.'<>'.$comment.'<>'.$date."\n";
|
252
|
+
|
253
|
+
file_put_contents($filename,$post, FILE_APPEND);
|
254
|
+
|
255
|
+
$password1=$_POST["password1"];
|
256
|
+
|
257
|
+
file_put_contents($passfile, $num.'<>'.$password1."\n", FILE_APPEND);
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
}
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
//削除
|
266
|
+
|
267
|
+
if(!empty($_POST["password2"])) {
|
268
|
+
|
269
|
+
$password2=$_POST["password2"];
|
270
|
+
|
271
|
+
$pass2=file($passfile);
|
272
|
+
|
273
|
+
$fp2=fopen($passfile, 'r+');
|
274
|
+
|
275
|
+
foreach($pass2 as $word2) {
|
276
|
+
|
277
|
+
$PASS2=explode('<>', trim($word2));
|
278
|
+
|
279
|
+
$id=$PASS2[1];
|
280
|
+
|
281
|
+
if( ($id==$password2)&&(!empty($_POST["delete"])) ) {
|
282
|
+
|
283
|
+
$delete=$_POST["delete"];
|
284
|
+
|
285
|
+
$lines=file($filename);
|
286
|
+
|
287
|
+
$fp=fopen($filename, 'w');
|
288
|
+
|
289
|
+
foreach($lines as $line) {
|
290
|
+
|
291
|
+
$LINE=explode('<>', $line);
|
292
|
+
|
293
|
+
$no=$LINE[0];
|
294
|
+
|
295
|
+
if($no!=$delete) {
|
296
|
+
|
297
|
+
fwrite($fp, $line);
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
}
|
302
|
+
|
303
|
+
fclose($fp);
|
304
|
+
|
305
|
+
}
|
306
|
+
|
307
|
+
}
|
308
|
+
|
309
|
+
fclose($fp2);
|
310
|
+
|
311
|
+
}
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
$contents=file($filename);
|
316
|
+
|
317
|
+
foreach($contents as $content) {
|
318
|
+
|
319
|
+
$Ndata=explode('<>', $content);
|
320
|
+
|
321
|
+
$Ydata=implode(" ", $Ndata);
|
322
|
+
|
323
|
+
print_r($Ydata);
|
324
|
+
|
325
|
+
echo "<br />";
|
326
|
+
|
327
|
+
}
|
328
|
+
|
329
|
+
?>
|
330
|
+
|
331
|
+
```
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
```php2
|
336
|
+
|
337
|
+
<?php
|
338
|
+
|
339
|
+
//接続
|
340
|
+
|
341
|
+
$dsn = 'mysql:dbname=??_???_????_????_???;host=localhost';
|
342
|
+
|
343
|
+
$user = '??-???.????-????';
|
344
|
+
|
345
|
+
$password = '????????';
|
346
|
+
|
347
|
+
$pdo = new PDO($dsn,$user,$password);
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
//テーブル作成
|
352
|
+
|
353
|
+
$sql = "CREATE TABLE H2O"
|
354
|
+
|
355
|
+
." ("
|
356
|
+
|
357
|
+
. "id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,"
|
358
|
+
|
359
|
+
. "name char(32),"
|
360
|
+
|
361
|
+
. "comment TEXT"
|
362
|
+
|
363
|
+
.");";
|
364
|
+
|
365
|
+
$stmt = $pdo->query($sql);
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
//入力
|
370
|
+
|
371
|
+
if( (!empty($_POST["name"])&&($_POST["comment"])&&($_POST["password1"])) && (empty($_POST["edit"])) ) {
|
372
|
+
|
373
|
+
$sql = $pdo -> prepare("INSERT INTO H2O (name, comment, password1) VALUES (:name, :comment :password1)");
|
374
|
+
|
375
|
+
$sql -> bindParam(':name', $name, PDO::PARAM_STR);
|
376
|
+
|
377
|
+
$sql -> bindParam(':comment', $comment, PDO::PARAM_STR);
|
378
|
+
|
379
|
+
$sql -> bindParam(':password1', $password1, PDO::PARAM_STR);
|
380
|
+
|
381
|
+
$name = $_POST["name"];
|
382
|
+
|
383
|
+
$comment = $_POST["comment"];
|
384
|
+
|
385
|
+
$password1 = $_POST["password1"];
|
386
|
+
|
387
|
+
$sql -> execute();
|
388
|
+
|
389
|
+
}
|
390
|
+
|
391
|
+
|
392
|
+
|
35
393
|
//編集選択
|
36
394
|
|
395
|
+
if(!empty($_POST["password2"])) {
|
396
|
+
|
397
|
+
$password2 = $_POST["password2"];
|
398
|
+
|
399
|
+
$sql = 'SELECT * FROM H2O';
|
400
|
+
|
401
|
+
$results = $pdo -> query($sql);
|
402
|
+
|
403
|
+
foreach ($results as $row) {
|
404
|
+
|
405
|
+
$id = $row['password1'];
|
406
|
+
|
407
|
+
if( ($id == $password2) && (!empty($_POST["editing"])) ) {
|
408
|
+
|
409
|
+
$editing=$_POST["editing"];
|
410
|
+
|
411
|
+
foreach ($results as $row) {
|
412
|
+
|
413
|
+
$no = $row['id'];
|
414
|
+
|
415
|
+
if($no == $editing) {
|
416
|
+
|
417
|
+
$ID = $row['id'];
|
418
|
+
|
419
|
+
$NAME = $row['name'];
|
420
|
+
|
421
|
+
$COMMENT = $row['comment'];
|
422
|
+
|
423
|
+
}
|
424
|
+
|
425
|
+
}
|
426
|
+
|
427
|
+
}
|
428
|
+
|
429
|
+
}
|
430
|
+
|
431
|
+
}
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
//削除
|
436
|
+
|
37
437
|
if(!empty($_POST["password3"])) {
|
38
438
|
|
39
|
-
$password3=$_POST["password3"];
|
439
|
+
$password3 = $_POST["password3"];
|
440
|
+
|
40
|
-
|
441
|
+
$sql = 'SELECT * FROM H2O';
|
442
|
+
|
41
|
-
$
|
443
|
+
$results = $pdo -> query($sql);
|
42
|
-
|
444
|
+
|
43
|
-
foreach($
|
445
|
+
foreach ($results as $row) {
|
44
|
-
|
446
|
+
|
45
|
-
$
|
447
|
+
$id = $row['password1'];
|
46
|
-
|
47
|
-
|
448
|
+
|
48
|
-
|
49
|
-
if( ($id==$password3)&&(!empty($_POST["e
|
449
|
+
if( ($id == $password3) && (!empty($_POST["delete"])) ) {
|
50
|
-
|
450
|
+
|
51
|
-
$e
|
451
|
+
$delete = $_POST["delete"];
|
52
|
-
|
53
|
-
|
452
|
+
|
54
|
-
|
55
|
-
foreach($e
|
453
|
+
foreach ($results as $row) {
|
56
|
-
|
454
|
+
|
57
|
-
$
|
455
|
+
$no = $row['id'];
|
58
|
-
|
59
|
-
|
456
|
+
|
60
|
-
|
61
|
-
if($
|
457
|
+
if($no != $delete) {
|
62
|
-
|
63
|
-
|
458
|
+
|
64
|
-
|
65
|
-
$
|
459
|
+
$sql = "delete from H2O where id=$no";
|
66
|
-
|
460
|
+
|
67
|
-
$
|
461
|
+
$result = $pdo->query($sql);
|
68
462
|
|
69
463
|
}
|
70
464
|
|
@@ -76,46 +470,6 @@
|
|
76
470
|
|
77
471
|
}
|
78
472
|
|
79
|
-
|
80
|
-
|
81
|
-
//編集実行
|
82
|
-
|
83
|
-
if( (!empty($_POST["edit"]))&&(empty($_POST["password1"])) ) {
|
84
|
-
|
85
|
-
$edit=$_POST["edit"];
|
86
|
-
|
87
|
-
$Editors=file($filename);
|
88
|
-
|
89
|
-
$fp=fopen($filename, 'w');
|
90
|
-
|
91
|
-
foreach($Editors as $Editor) {
|
92
|
-
|
93
|
-
$EDIT=explode('<>', $Editor);
|
94
|
-
|
95
|
-
$NO=current(array_slice($EDIT, 0, 1));
|
96
|
-
|
97
|
-
if($NO==$edit) {
|
98
|
-
|
99
|
-
$name=$_POST["name"];
|
100
|
-
|
101
|
-
$comment=$_POST["comment"];
|
102
|
-
|
103
|
-
$date=date('Y/m/d H:i');
|
104
|
-
|
105
|
-
fwrite($fp, $edit.'<>'.$name.'<>'.$comment.'<>'.$date."\n");
|
106
|
-
|
107
|
-
} else {
|
108
|
-
|
109
|
-
fwrite($fp, $Editor);
|
110
|
-
|
111
|
-
}
|
112
|
-
|
113
|
-
}
|
114
|
-
|
115
|
-
fclose($fp);
|
116
|
-
|
117
|
-
}
|
118
|
-
|
119
473
|
?>
|
120
474
|
|
121
475
|
|
@@ -128,7 +482,7 @@
|
|
128
482
|
|
129
483
|
<meta charset="UTF-8" />
|
130
484
|
|
131
|
-
<title>
|
485
|
+
<title>H2O</title>
|
132
486
|
|
133
487
|
</head>
|
134
488
|
|
@@ -156,422 +510,68 @@
|
|
156
510
|
|
157
511
|
<input type="text" name="password1" placeholder="パスワード">
|
158
512
|
|
159
|
-
<input type="submit" value="
|
513
|
+
<input type="submit" value="投稿"> <br />
|
160
514
|
|
161
515
|
<br />
|
162
516
|
|
163
517
|
|
164
518
|
|
519
|
+
<!--編集選択-->
|
520
|
+
|
521
|
+
<input type="text" name="editing" placeholder="編集対象番号"> <br />
|
522
|
+
|
523
|
+
<input type="text" name="password2" placeholder="パスワード">
|
524
|
+
|
525
|
+
<input type="submit" value="編集"> <br />
|
526
|
+
|
527
|
+
<br />
|
528
|
+
|
529
|
+
|
530
|
+
|
165
|
-
<!--削除-->
|
531
|
+
<!--削除-->
|
166
532
|
|
167
533
|
<input type="text" name="delete" placeholder="削除対象番号"> <br />
|
168
534
|
|
169
|
-
<input type="text" name="password
|
535
|
+
<input type="text" name="password3" placeholder="パスワード">
|
170
536
|
|
171
537
|
<input type="submit" value="削除"> <br />
|
172
538
|
|
173
|
-
<br />
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
<!--編集選択-->
|
178
|
-
|
179
|
-
<input type="text" name="editing" placeholder="編集対象番号"> <br />
|
180
|
-
|
181
|
-
<input type="text" name="password3" placeholder="パスワード">
|
182
|
-
|
183
|
-
<input type="submit" value="編集"> <br />
|
184
|
-
|
185
539
|
</p>
|
186
540
|
|
187
541
|
</form>
|
188
542
|
|
543
|
+
|
544
|
+
|
545
|
+
<?php
|
546
|
+
|
547
|
+
//入力確認 データ検索?
|
548
|
+
|
549
|
+
$sql = 'SELECT * FROM H2O';
|
550
|
+
|
551
|
+
$results = $pdo -> query($sql);
|
552
|
+
|
553
|
+
foreach ($results as $row) {
|
554
|
+
|
555
|
+
echo $row['id'].',';
|
556
|
+
|
557
|
+
echo $row['name'].',';
|
558
|
+
|
559
|
+
echo $row['comment'].'<br>';
|
560
|
+
|
561
|
+
}
|
562
|
+
|
563
|
+
?>
|
564
|
+
|
565
|
+
|
566
|
+
|
189
567
|
</body>
|
190
568
|
|
191
569
|
</html>
|
192
570
|
|
193
|
-
|
194
|
-
|
195
|
-
<?php
|
196
|
-
|
197
|
-
//変数に代入
|
198
|
-
|
199
|
-
$filename='mission_2-5_ver2.txt';
|
200
|
-
|
201
|
-
$passfile='mission_2-5_pass_ver2.txt';
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
//新規投稿
|
206
|
-
|
207
|
-
if( (!empty($_POST["name"])&&($_POST["comment"])&&($_POST["password1"])) && (empty($_POST["edit"])) ) {
|
208
|
-
|
209
|
-
if(empty($filename)) {
|
210
|
-
|
211
|
-
$name=$_POST["name"];
|
212
|
-
|
213
|
-
$comment=$_POST["comment"];
|
214
|
-
|
215
|
-
$number=count(file($filename));
|
216
|
-
|
217
|
-
$num=$number++;
|
218
|
-
|
219
|
-
$date=date('Y/m/d H:i');
|
220
|
-
|
221
|
-
$post=$num.'<>'.$name.'<>'.$comment.'<>'.$date."\n";
|
222
|
-
|
223
|
-
file_put_contents($filename, $post, FILE_APPEND);
|
224
|
-
|
225
|
-
$password1=$_POST["password1"];
|
226
|
-
|
227
|
-
file_put_contents($passfile, $num.'<>'.$password1."\n", FILE_APPEND);
|
228
|
-
|
229
|
-
} else {
|
230
|
-
|
231
|
-
$name=$_POST["name"];
|
232
|
-
|
233
|
-
$comment=$_POST["comment"];
|
234
|
-
|
235
|
-
$date=date('Y/m/d H:i');
|
236
|
-
|
237
|
-
$lines=file($filename);
|
238
|
-
|
239
|
-
$number=0;
|
240
|
-
|
241
|
-
foreach($lines as $line) {
|
242
|
-
|
243
|
-
$array=explode('<>', $line);
|
244
|
-
|
245
|
-
$id=$array[0];
|
246
|
-
|
247
|
-
}
|
248
|
-
|
249
|
-
$num=$id+1;
|
250
|
-
|
251
|
-
$post=$num.'<>'.$name.'<>'.$comment.'<>'.$date."\n";
|
252
|
-
|
253
|
-
file_put_contents($filename,$post, FILE_APPEND);
|
254
|
-
|
255
|
-
$password1=$_POST["password1"];
|
256
|
-
|
257
|
-
file_put_contents($passfile, $num.'<>'.$password1."\n", FILE_APPEND);
|
258
|
-
|
259
|
-
}
|
260
|
-
|
261
|
-
}
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
//削除
|
266
|
-
|
267
|
-
if(!empty($_POST["password2"])) {
|
268
|
-
|
269
|
-
$password2=$_POST["password2"];
|
270
|
-
|
271
|
-
$pass2=file($passfile);
|
272
|
-
|
273
|
-
$fp2=fopen($passfile, 'r+');
|
274
|
-
|
275
|
-
foreach($pass2 as $word2) {
|
276
|
-
|
277
|
-
$PASS2=explode('<>', trim($word2));
|
278
|
-
|
279
|
-
$id=$PASS2[1];
|
280
|
-
|
281
|
-
if( ($id==$password2)&&(!empty($_POST["delete"])) ) {
|
282
|
-
|
283
|
-
$delete=$_POST["delete"];
|
284
|
-
|
285
|
-
$lines=file($filename);
|
286
|
-
|
287
|
-
$fp=fopen($filename, 'w');
|
288
|
-
|
289
|
-
foreach($lines as $line) {
|
290
|
-
|
291
|
-
$LINE=explode('<>', $line);
|
292
|
-
|
293
|
-
$no=$LINE[0];
|
294
|
-
|
295
|
-
if($no!=$delete) {
|
296
|
-
|
297
|
-
fwrite($fp, $line);
|
298
|
-
|
299
|
-
}
|
300
|
-
|
301
|
-
}
|
302
|
-
|
303
|
-
fclose($fp);
|
304
|
-
|
305
|
-
}
|
306
|
-
|
307
|
-
}
|
308
|
-
|
309
|
-
fclose($fp2);
|
310
|
-
|
311
|
-
}
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
$contents=file($filename);
|
316
|
-
|
317
|
-
foreach($contents as $content) {
|
318
|
-
|
319
|
-
$Ndata=explode('<>', $content);
|
320
|
-
|
321
|
-
$Ydata=implode(" ", $Ndata);
|
322
|
-
|
323
|
-
print_r($Ydata);
|
324
|
-
|
325
|
-
echo "<br />";
|
326
|
-
|
327
|
-
}
|
328
|
-
|
329
|
-
?>
|
330
|
-
|
331
571
|
```
|
332
572
|
|
333
573
|
|
334
574
|
|
335
|
-
```php2
|
336
|
-
|
337
|
-
<?php
|
338
|
-
|
339
|
-
//接続
|
340
|
-
|
341
|
-
$dsn = 'mysql:dbname=tt_356_99sv_coco_com;host=localhost';
|
342
|
-
|
343
|
-
$user = 'tt-356.99sv-coco';
|
344
|
-
|
345
|
-
$password = 'i4PGU7sM';
|
346
|
-
|
347
|
-
$pdo = new PDO($dsn,$user,$password);
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
//テーブル作成
|
352
|
-
|
353
|
-
$sql = "CREATE TABLE H2O"
|
354
|
-
|
355
|
-
." ("
|
356
|
-
|
357
|
-
. "id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,"
|
358
|
-
|
359
|
-
. "name char(32),"
|
360
|
-
|
361
|
-
. "comment TEXT"
|
362
|
-
|
363
|
-
.");";
|
364
|
-
|
365
|
-
$stmt = $pdo->query($sql);
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
//入力
|
370
|
-
|
371
|
-
if( (!empty($_POST["name"])&&($_POST["comment"])&&($_POST["password1"])) && (empty($_POST["edit"])) ) {
|
372
|
-
|
373
|
-
$sql = $pdo -> prepare("INSERT INTO H2O (name, comment, password1) VALUES (:name, :comment :password1)");
|
374
|
-
|
375
|
-
$sql -> bindParam(':name', $name, PDO::PARAM_STR);
|
376
|
-
|
377
|
-
$sql -> bindParam(':comment', $comment, PDO::PARAM_STR);
|
378
|
-
|
379
|
-
$sql -> bindParam(':password1', $password1, PDO::PARAM_STR);
|
380
|
-
|
381
|
-
$name = $_POST["name"];
|
382
|
-
|
383
|
-
$comment = $_POST["comment"];
|
384
|
-
|
385
|
-
$password1 = $_POST["password1"];
|
386
|
-
|
387
|
-
$sql -> execute();
|
388
|
-
|
389
|
-
}
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
//編集選択
|
394
|
-
|
395
|
-
if(!empty($_POST["password2"])) {
|
396
|
-
|
397
|
-
$password2 = $_POST["password2"];
|
398
|
-
|
399
|
-
$sql = 'SELECT * FROM H2O';
|
400
|
-
|
401
|
-
$results = $pdo -> query($sql);
|
402
|
-
|
403
|
-
foreach ($results as $row) {
|
404
|
-
|
405
|
-
$id = $row['password1'];
|
406
|
-
|
407
|
-
if( ($id == $password2) && (!empty($_POST["editing"])) ) {
|
408
|
-
|
409
|
-
$editing=$_POST["editing"];
|
410
|
-
|
411
|
-
foreach ($results as $row) {
|
412
|
-
|
413
|
-
$no = $row['id'];
|
414
|
-
|
415
|
-
if($no == $editing) {
|
416
|
-
|
417
|
-
$ID = $row['id'];
|
418
|
-
|
419
|
-
$NAME = $row['name'];
|
420
|
-
|
421
|
-
$COMMENT = $row['comment'];
|
422
|
-
|
423
|
-
}
|
424
|
-
|
425
|
-
}
|
426
|
-
|
427
|
-
}
|
428
|
-
|
429
|
-
}
|
430
|
-
|
431
|
-
}
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
//削除
|
436
|
-
|
437
|
-
if(!empty($_POST["password3"])) {
|
438
|
-
|
439
|
-
$password3 = $_POST["password3"];
|
440
|
-
|
441
|
-
$sql = 'SELECT * FROM H2O';
|
442
|
-
|
443
|
-
$results = $pdo -> query($sql);
|
444
|
-
|
445
|
-
foreach ($results as $row) {
|
446
|
-
|
447
|
-
$id = $row['password1'];
|
448
|
-
|
449
|
-
if( ($id == $password3) && (!empty($_POST["delete"])) ) {
|
450
|
-
|
451
|
-
$delete = $_POST["delete"];
|
452
|
-
|
453
|
-
foreach ($results as $row) {
|
454
|
-
|
455
|
-
$no = $row['id'];
|
456
|
-
|
457
|
-
if($no != $delete) {
|
458
|
-
|
459
|
-
$sql = "delete from H2O where id=$no";
|
460
|
-
|
461
|
-
$result = $pdo->query($sql);
|
462
|
-
|
463
|
-
}
|
464
|
-
|
465
|
-
}
|
466
|
-
|
467
|
-
}
|
468
|
-
|
469
|
-
}
|
470
|
-
|
471
|
-
}
|
472
|
-
|
473
|
-
?>
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
<!DOCTYPE html>
|
478
|
-
|
479
|
-
<html lang="ja">
|
480
|
-
|
481
|
-
<head>
|
482
|
-
|
483
|
-
<meta charset="UTF-8" />
|
484
|
-
|
485
|
-
<title>掲示板</title>
|
486
|
-
|
487
|
-
</head>
|
488
|
-
|
489
|
-
<body>
|
490
|
-
|
491
|
-
<form method="POST" action=" ">
|
492
|
-
|
493
|
-
<p>
|
494
|
-
|
495
|
-
<!--投稿-->
|
496
|
-
|
497
|
-
<input type="text" name="name" placeholder="名前" value="<?php echo $NAME ?>"> <br />
|
498
|
-
|
499
|
-
<input type="text" name="comment" placeholder="コメント" value="<?php echo $COMMENT ?>"> <br />
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
<!--編集実行-->
|
504
|
-
|
505
|
-
<input type="hidden" name="edit" value="<?php echo $ID ?>"> <br />
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
<!--パスワード欄-->
|
510
|
-
|
511
|
-
<input type="text" name="password1" placeholder="パスワード">
|
512
|
-
|
513
|
-
<input type="submit" value="投稿"> <br />
|
514
|
-
|
515
|
-
<br />
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
<!--編集選択-->
|
520
|
-
|
521
|
-
<input type="text" name="editing" placeholder="編集対象番号"> <br />
|
522
|
-
|
523
|
-
<input type="text" name="password2" placeholder="パスワード">
|
524
|
-
|
525
|
-
<input type="submit" value="編集"> <br />
|
526
|
-
|
527
|
-
<br />
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
<!--削除-->
|
532
|
-
|
533
|
-
<input type="text" name="delete" placeholder="削除対象番号"> <br />
|
534
|
-
|
535
|
-
<input type="text" name="password3" placeholder="パスワード">
|
536
|
-
|
537
|
-
<input type="submit" value="削除"> <br />
|
538
|
-
|
539
|
-
</p>
|
540
|
-
|
541
|
-
</form>
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
<?php
|
546
|
-
|
547
|
-
//入力確認 データ検索?
|
548
|
-
|
549
|
-
$sql = 'SELECT * FROM H2O';
|
550
|
-
|
551
|
-
$results = $pdo -> query($sql);
|
552
|
-
|
553
|
-
foreach ($results as $row) {
|
554
|
-
|
555
|
-
echo $row['id'].',';
|
556
|
-
|
557
|
-
echo $row['name'].',';
|
558
|
-
|
559
|
-
echo $row['comment'].'<br>';
|
560
|
-
|
561
|
-
}
|
562
|
-
|
563
|
-
?>
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
</body>
|
568
|
-
|
569
|
-
</html>
|
570
|
-
|
571
|
-
```
|
572
|
-
|
573
|
-
|
574
|
-
|
575
575
|
|
576
576
|
|
577
577
|
### 補足情報(FW/ツールのバージョンなど)
|