回答編集履歴

4

追記

2017/05/18 12:22

投稿

s8_chu
s8_chu

スコア14731

test CHANGED
@@ -139,3 +139,165 @@
139
139
  ?>
140
140
 
141
141
  ```
142
+
143
+
144
+
145
+ #追記2
146
+
147
+ `aciton属性`ではなくて、`action属性`です。
148
+
149
+ ```HTML
150
+
151
+ <!DOCTYPE html>
152
+
153
+ <html>
154
+
155
+ <head>
156
+
157
+ <meta charset="UTF-8">
158
+
159
+ <title>ろくまる農園</title>
160
+
161
+ </head>
162
+
163
+ <body>
164
+
165
+
166
+
167
+ スタッフ追加<br/>
168
+
169
+ <br/>
170
+
171
+ <form method="post" action="staff_add_check.php"><!-- action="staff_add_check.php"に修正 -->
172
+
173
+ スタッフ名を入力してください<br/>
174
+
175
+ <input type="text" name="name" style="width:200px"><br/>
176
+
177
+ パスワードを入力して下さい<br/>
178
+
179
+ <input type="password" name="pass" style="width:100px"><br/>
180
+
181
+ パスワードをもう一度入力してください<br/>
182
+
183
+ <input type="password" name="pass2" style="width:100px"><br/>
184
+
185
+ <br/>
186
+
187
+ <input type="button" onclick="history.back()" value="戻る">
188
+
189
+ <input type="submit" value="OK">
190
+
191
+ </body>
192
+
193
+ </html>
194
+
195
+ ```
196
+
197
+ ```PHP
198
+
199
+ <?php
200
+
201
+ if (isset($_POST["name"]) &&
202
+
203
+ isset($_POST["pass"]) &&
204
+
205
+ isset($_POST["pass2"])
206
+
207
+ ) {
208
+
209
+ $staff_name = $_POST['name'];
210
+
211
+ $staff_pass = $_POST['pass'];
212
+
213
+ $staff_pass2 = $_POST['pass2'];
214
+
215
+ $staff_name = htmlspecialchars($staff_name, ENT_QUOTES, 'UTF-8');
216
+
217
+ $staff_pass = htmlspecialchars($staff_pass, ENT_QUOTES, 'UTF-8');
218
+
219
+ $staff_pass2 = htmlspecialchars($staff_pass2, ENT_QUOTES, 'UTF-8');
220
+
221
+
222
+
223
+ if ($staff_name == ' ') {
224
+
225
+
226
+
227
+ print 'スタッフ名が入力されていません<br />';
228
+
229
+
230
+
231
+ } else {
232
+
233
+
234
+
235
+ print 'スタッフ名:';
236
+
237
+ print $staff_name;
238
+
239
+ print '<br />';
240
+
241
+ }
242
+
243
+
244
+
245
+ if ($staff_pass == ' ') {
246
+
247
+
248
+
249
+ print 'パスワードが入力されていません<br />';
250
+
251
+
252
+
253
+ }
254
+
255
+
256
+
257
+ if ($staff_pass != $staff_pass2) {
258
+
259
+
260
+
261
+ print 'パスワードが一致しません<br />';
262
+
263
+
264
+
265
+ }
266
+
267
+
268
+
269
+ if ($staff_name == '' || $staff_pass == '' || $staff_pass != $staff_pass2) {
270
+
271
+ print '<form>';
272
+
273
+ print '<input type="button" onclick="history.back()" value="戻る">';
274
+
275
+ print '</form>';
276
+
277
+
278
+
279
+ } else {
280
+
281
+ $staff_pass = md5($staff_pass);
282
+
283
+ print '<form method="post" action="staff_add_done.php">';
284
+
285
+ print '<input type="hidden" name="name" value="' . $staff_name . '">';
286
+
287
+ print '<input type="hidden" name="pass" value="' . $staff_pass . '">';
288
+
289
+ print '<br />';
290
+
291
+ print '<input type="button" onclick="history.back()" value="戻る">';
292
+
293
+ print '<input type="submit" value="OK">';
294
+
295
+ print '</form>';
296
+
297
+ }
298
+
299
+ }
300
+
301
+ ?>
302
+
303
+ ```

3

修正、追記

2017/05/18 12:22

投稿

s8_chu
s8_chu

スコア14731

test CHANGED
@@ -24,7 +24,7 @@
24
24
 
25
25
  #追記
26
26
 
27
- `$_POST["name"]`、`$_POST["pass"]`、`$_POST["pass2"]`が定義されていないときには`$staff_name`、`$staff_pass`、`$staff_pass2`という変数が定義されないことになりますから、それが原因で`Undefined variable`というエラーが発生します。`$_POST["name"]`、`$_POST["pass"]`、`$_POST["pass2"]`が定義されていないときにはしなくて良い処理をif文の中に入れることで解決できると思います。
27
+ 上のコードをそのまま使うと`$_POST["name"]`、`$_POST["pass"]`、`$_POST["pass2"]`が定義されていないときには`$staff_name`、`$staff_pass`、`$staff_pass2`という変数が定義されないことになりますから、それが原因で`Undefined variable`というエラーが発生します。`$_POST["name"]`、`$_POST["pass"]`、`$_POST["pass2"]`が定義されていないときにはしなくて良い処理をif文の中に入れることで解決できると思います。
28
28
 
29
29
  質問の趣旨とは関係ありませんが、`oneclick="history.back()"`ではなく、`onclick="history.back()"`ではないかと思いますがいかがでしょう。
30
30
 

2

追記

2017/05/18 12:03

投稿

s8_chu
s8_chu

スコア14731

test CHANGED
@@ -21,3 +21,121 @@
21
21
  }
22
22
 
23
23
  ```
24
+
25
+ #追記
26
+
27
+ `$_POST["name"]`、`$_POST["pass"]`、`$_POST["pass2"]`が定義されていないときには`$staff_name`、`$staff_pass`、`$staff_pass2`という変数が定義されないことになりますから、それが原因で`Undefined variable`というエラーが発生します。`$_POST["name"]`、`$_POST["pass"]`、`$_POST["pass2"]`が定義されていないときにはしなくて良い処理をif文の中に入れることで解決できると思います。
28
+
29
+ 質問の趣旨とは関係ありませんが、`oneclick="history.back()"`ではなく、`onclick="history.back()"`ではないかと思いますがいかがでしょう。
30
+
31
+ ```PHP
32
+
33
+ <?php
34
+
35
+ if (isset($_POST["name"]) &&
36
+
37
+ isset($_POST["pass"]) &&
38
+
39
+ isset($_POST["pass2"])
40
+
41
+ ) {
42
+
43
+ $staff_name = $_POST['name'];
44
+
45
+ $staff_pass = $_POST['pass'];
46
+
47
+ $staff_pass2 = $_POST['pass2'];
48
+
49
+ $staff_name = htmlspecialchars($staff_name, ENT_QUOTES, 'UTF-8');
50
+
51
+ $staff_pass = htmlspecialchars($staff_pass, ENT_QUOTES, 'UTF-8');
52
+
53
+ $staff_pass2 = htmlspecialchars($staff_pass2, ENT_QUOTES, 'UTF-8');
54
+
55
+
56
+
57
+ if ($staff_name == ' ') {
58
+
59
+
60
+
61
+ print 'スタッフ名が入力されていません<br />';
62
+
63
+
64
+
65
+ } else {
66
+
67
+
68
+
69
+ print 'スタッフ名:';
70
+
71
+ print $staff_name;
72
+
73
+ print '<br />';
74
+
75
+ }
76
+
77
+
78
+
79
+ if ($staff_pass == ' ') {
80
+
81
+
82
+
83
+ print 'パスワードが入力されていません<br />';
84
+
85
+
86
+
87
+ }
88
+
89
+
90
+
91
+ if ($staff_pass != $staff_pass2) {
92
+
93
+
94
+
95
+ print 'パスワードが一致しません<br />';
96
+
97
+
98
+
99
+ }
100
+
101
+
102
+
103
+ if ($staff_name == '' || $staff_pass == '' || $staff_pass != $staff_pass2) {
104
+
105
+
106
+
107
+ print '<form>';
108
+
109
+ print '<input type="button" oneclick="history.back()" value="戻る">';
110
+
111
+ print '</form>';
112
+
113
+
114
+
115
+ } else {
116
+
117
+ $staff_pass = md5($staff_pass);
118
+
119
+ print '<form method="post" action="staff_add_done.php">';
120
+
121
+ print '<input type="hidden" name="name" value="' . $staff_name . '">';
122
+
123
+ print '<input type="hidden" name="pass" value="' . $staff_pass . '">';
124
+
125
+ print '<br />';
126
+
127
+ print '<input type="button" oneclick="history.back()" value="戻る">';
128
+
129
+ print '<input type="submit" value="OK">';
130
+
131
+ print '</form>';
132
+
133
+
134
+
135
+ }
136
+
137
+ }
138
+
139
+ ?>
140
+
141
+ ```

1

追記

2017/05/18 11:46

投稿

s8_chu
s8_chu

スコア14731

test CHANGED
@@ -1,4 +1,4 @@
1
- `Undefined index`は定義していない配列を使用したときに発生するエラーです。[isset](http://php.net/manual/ja/function.isset.php)を使用することで解決できると思います。
1
+ `Undefined index`は定義していない配列を使用したときに発生するエラーです。[isset](http://php.net/manual/ja/function.isset.php)を使用して使おうとしている配列が定義されているか確認することで解決できると思います。
2
2
 
3
3
  ```PHP
4
4