質問編集履歴
2
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
パスワードを入力して一致した場合に指定した番号のデータを
|
5
|
+
パスワードを入力して一致した場合に指定した番号のデータを投稿フォームに表示し、その値を編集すること。
|
6
6
|
|
7
7
|
|
8
8
|
|
9
9
|
### 発生している問題・エラーメッセージ
|
10
10
|
|
11
|
-
パスワードを入力しても
|
11
|
+
正しいパスワードを入力しても、投稿フォームに編集したい値が入力されず、編集ができない。
|
12
12
|
|
13
13
|
### 該当のソースコード
|
14
14
|
|
@@ -36,156 +36,220 @@
|
|
36
36
|
|
37
37
|
//接続省略
|
38
38
|
|
39
|
-
//table作成
|
39
|
+
/*//table作成
|
40
|
-
|
40
|
+
|
41
|
-
$sql = "CREATE TABLE IF NOT EXISTS keii
|
41
|
+
$sql = "CREATE TABLE IF NOT EXISTS keijiban"
|
42
42
|
|
43
43
|
. "("
|
44
44
|
|
45
45
|
. "id INT AUTO_INCREMENT PRIMARY KEY,"
|
46
46
|
|
47
|
-
. "name
|
47
|
+
. "name CHAR(32),"
|
48
|
-
|
48
|
+
|
49
|
-
. "comment
|
49
|
+
. "comment VARCHAR(100),"
|
50
|
-
|
50
|
+
|
51
|
-
. "date
|
51
|
+
. "date CHAR(100),"
|
52
|
-
|
52
|
+
|
53
|
-
. "password INT(
|
53
|
+
. "password INT(100)"
|
54
54
|
|
55
55
|
. ")";
|
56
56
|
|
57
57
|
$stmt = $pdo->query($sql);
|
58
58
|
|
59
|
+
*/
|
60
|
+
|
59
61
|
//変数に代入
|
60
62
|
|
61
63
|
$date = date("Y/m/d/ H:i:s");
|
62
64
|
|
63
|
-
|
65
|
+
$name = $_POST['name'];
|
66
|
+
|
67
|
+
$comment = $_POST['comment'];
|
68
|
+
|
69
|
+
$pass = $_POST['pass'];
|
64
70
|
|
65
71
|
//投稿機能
|
66
72
|
|
67
|
-
if(!empty($name) && !empty($comment) && !empty($pass
|
73
|
+
if(!empty($_POST['name']) && !empty($_POST['comment']) && !empty($_POST['pass'])){
|
74
|
+
|
75
|
+
$sql = $pdo -> prepare("INSERT INTO keijiban (name, comment, date, password) VALUES (:name, :comment, :date, :password)");
|
76
|
+
|
77
|
+
$sql -> bindParam(':name', $name, PDO::PARAM_STR);
|
78
|
+
|
79
|
+
$sql -> bindParam(':comment', $comment, PDO::PARAM_STR);
|
80
|
+
|
81
|
+
$sql -> bindParam(':date', $date, PDO::PARAM_STR);
|
82
|
+
|
83
|
+
$sql -> bindParam(':password', $pass, PDO::PARAM_INT);
|
84
|
+
|
85
|
+
$sql -> execute();
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
//削除機能
|
92
|
+
|
93
|
+
//変数に代入
|
94
|
+
|
95
|
+
$delete = $_POST['delete'];
|
96
|
+
|
97
|
+
$dpass = $_POST['dpass'] ;
|
98
|
+
|
99
|
+
if(!empty($_POST['delete']) && !empty($_POST['dpass'] )) {
|
100
|
+
|
101
|
+
$sql = 'DELETE FROM keijiban WHERE id=:id';
|
102
|
+
|
103
|
+
$stmt = $pdo->prepare($sql);
|
104
|
+
|
105
|
+
$stmt->execute(array(':id' => $_POST['delete']));
|
106
|
+
|
107
|
+
$results = $stmt->fetchAll();
|
108
|
+
|
109
|
+
foreach ($results as $row) {
|
110
|
+
|
111
|
+
if ($dpass == $row['password']){
|
112
|
+
|
113
|
+
$stmt->bindParam(':id', $delete, PDO::PARAM_INT);
|
114
|
+
|
115
|
+
$stmt->execute();
|
116
|
+
|
117
|
+
}else{
|
118
|
+
|
119
|
+
echo "パスワードが違います<br>";
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
//編集機能
|
130
|
+
|
131
|
+
//変数に代入
|
132
|
+
|
133
|
+
$edit = $_POST['edit'];
|
134
|
+
|
135
|
+
$date = date("Y/m/d/ H:i:s");
|
68
136
|
|
69
137
|
$name = $_POST['name'];
|
70
138
|
|
71
139
|
$comment = $_POST['comment'];
|
72
140
|
|
141
|
+
$epass = $_POST['epass'];
|
142
|
+
|
143
|
+
if(!empty($_POST['edit']) && !empty($_POST['epass'] )) {
|
144
|
+
|
145
|
+
$sql = 'UPDATE keijiban SET id=:id,name=:name,comment=:comment,date=:date,password=:password WHERE id=:id';
|
146
|
+
|
147
|
+
$stmt = $pdo->prepare($sql);
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
$results = $stmt->fetchAll();
|
152
|
+
|
153
|
+
foreach($results as $row) {
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
if($edit == $row['id'] && $epass == $row['password']) {
|
158
|
+
|
159
|
+
$ename = $row['name'];
|
160
|
+
|
161
|
+
$ecom = $row['comment'];
|
162
|
+
|
73
|
-
$pass
|
163
|
+
$epass = $row['password'];
|
74
|
-
|
75
|
-
|
164
|
+
|
76
|
-
|
165
|
+
|
166
|
+
|
77
|
-
$s
|
167
|
+
$stmt->bindParam(':name', $name, PDO::PARAM_STR);
|
78
|
-
|
168
|
+
|
79
|
-
$s
|
169
|
+
$stmt->bindParam(':comment', $comment, PDO::PARAM_STR);
|
80
|
-
|
170
|
+
|
81
|
-
$s
|
171
|
+
$stmt->bindParam(':date', $date, PDO::PARAM_STR);
|
82
|
-
|
172
|
+
|
83
|
-
$s
|
173
|
+
$stmt->bindParam(':password', $epass, PDO::PARAM_INT);
|
84
|
-
|
174
|
+
|
85
|
-
$s
|
175
|
+
$stmt->execute();
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
}else{
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
$sql = 'SELECT * FROM keijiban';
|
188
|
+
|
189
|
+
$stmt = $pdo->query($sql);
|
190
|
+
|
191
|
+
$stmt->execute();
|
86
192
|
|
87
193
|
}
|
88
194
|
|
89
195
|
|
90
196
|
|
197
|
+
?>
|
198
|
+
|
199
|
+
<form action="" method="post">
|
200
|
+
|
201
|
+
<input type="text" name="name" placeholder="名前" value="<?php if(isset($ename)){echo $ename;}?>"><br>
|
202
|
+
|
203
|
+
<input type="text" name="comment"placeholder="コメント" value="<?php if(isset($ecom)){echo $ecom;} ?>"><br>
|
204
|
+
|
205
|
+
<input type="text" name="pass" placeholder="パスワード"value="<?php if(isset($epass)){echo $epass;} ?>"><br>
|
206
|
+
|
207
|
+
<input type="submit" name="submit" value='投稿'><br>
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
<input type="number" name="delete" placeholder="削除対象番号"><br>
|
212
|
+
|
213
|
+
<input type="text" name="dpass" placeholder="パスワード"><br>
|
214
|
+
|
215
|
+
<input type="submit" name="submit" value="削除"><br>
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
<input type="number" name="edit" placeholder="編集対象番号"><br>
|
220
|
+
|
221
|
+
<input type="text" name="epass" placeholder="パスワード"><br>
|
222
|
+
|
223
|
+
<input type="submit" name="submit" value="編集">
|
224
|
+
|
91
|
-
/
|
225
|
+
</form>
|
92
|
-
|
93
|
-
|
226
|
+
|
94
|
-
|
95
|
-
|
227
|
+
|
96
|
-
|
228
|
+
|
97
|
-
|
229
|
+
<?php
|
98
|
-
|
230
|
+
|
99
|
-
$sql = 'SELECT * FROM keii
|
231
|
+
$sql = 'SELECT * FROM keijiban';
|
100
|
-
|
232
|
+
|
101
|
-
$stmt = $pdo->
|
233
|
+
$stmt = $pdo->query($sql);
|
102
|
-
|
103
|
-
$stmt->bindParam(':id', $delete, PDO::PARAM_INT);
|
104
|
-
|
105
|
-
$stmt->execute();
|
106
234
|
|
107
235
|
$results = $stmt->fetchAll();
|
108
236
|
|
109
|
-
foreach ($results as $row)
|
237
|
+
foreach ($results as $row){
|
110
|
-
|
111
|
-
|
238
|
+
|
112
|
-
|
113
|
-
$sql = 'DELETE FROM keiijban WHERE id=:id';
|
114
|
-
|
115
|
-
$stmt = $pdo->prepare($sql);
|
116
|
-
|
117
|
-
$stmt->bindParam(':id', $delete, PDO::PARAM_INT);
|
118
|
-
|
119
|
-
$stmt->execute();
|
120
|
-
|
121
|
-
}else{
|
122
|
-
|
123
|
-
|
239
|
+
echo $row['id'].' ';
|
240
|
+
|
124
|
-
|
241
|
+
echo $row['name'].' ';
|
242
|
+
|
243
|
+
echo $row['comment'].' ';
|
244
|
+
|
245
|
+
echo $row['date'].' ';
|
246
|
+
|
247
|
+
echo $row['password'].'<br>';
|
248
|
+
|
125
|
-
|
249
|
+
}
|
126
|
-
|
127
|
-
}
|
128
|
-
|
129
|
-
}
|
130
250
|
|
131
251
|
?>
|
132
252
|
|
133
|
-
<form action="" method="post">
|
134
|
-
|
135
|
-
<input type="text" name="name" placeholder="名前" value="<?php if(!empty($ename)){echo $ename;}?>"><br>
|
136
|
-
|
137
|
-
<input type="text" name="comment"placeholder="コメント" value="<?php if(!empty($ecom)){echo $ecom;} ?>"><br>
|
138
|
-
|
139
|
-
<input type="text" name="password" placeholder="パスワード"value="<?php if(!empty($epass)){echo $epass;} ?>"><br>
|
140
|
-
|
141
|
-
<input type="submit" name="submit"><br><hr>
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
<input type="number" name="delete" placeholder="削除対象番号"><br>
|
146
|
-
|
147
|
-
<input type="text" name="dpass" placeholder="パスワード">
|
148
|
-
|
149
|
-
<input type="submit" name="submit" value="削除"><br><hr>
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
<input type="number" name="edit" placeholder="編集対象番号"><br>
|
154
|
-
|
155
|
-
<input type="text" name="epass" placeholder="パスワード">
|
156
|
-
|
157
|
-
<input type="submit" name="submit" value="編集"><hr>
|
158
|
-
|
159
|
-
</form>
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
<?php
|
164
|
-
|
165
|
-
$sql = 'SELECT * FROM keiijban';
|
166
|
-
|
167
|
-
$stmt = $pdo->query($sql);
|
168
|
-
|
169
|
-
$results = $stmt->fetchAll();
|
170
|
-
|
171
|
-
foreach ($results as $row){
|
172
|
-
|
173
|
-
echo $row['id'].' ';
|
174
|
-
|
175
|
-
echo $row['name'].' ';
|
176
|
-
|
177
|
-
echo $row['comment'].' ';
|
178
|
-
|
179
|
-
echo $row['date'].' ';
|
180
|
-
|
181
|
-
echo $row['password'].'<br>';
|
182
|
-
|
183
|
-
echo '<hr>';
|
184
|
-
|
185
|
-
}
|
186
|
-
|
187
|
-
?>
|
188
|
-
|
189
253
|
|
190
254
|
|
191
255
|
</body>
|
@@ -194,4 +258,4 @@
|
|
194
258
|
|
195
259
|
```
|
196
260
|
|
197
|
-
|
261
|
+
編集機能のどこが間違っているのか分かりません。ご教授よろしくお願いします。
|
1
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,7 +24,7 @@
|
|
24
24
|
|
25
25
|
<meta charset="UTF-8">
|
26
26
|
|
27
|
-
<title>
|
27
|
+
<title>keijiban</title>
|
28
28
|
|
29
29
|
</head>
|
30
30
|
|