質問編集履歴

3

編集

2017/08/22 08:16

投稿

nrnrdsa
nrnrdsa

スコア19

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- ###前提・実現したいこと
1
+ ![イメージ説明](822a44c868d779624e4a6ffc6cb9f50c.png)###前提・実現したいこと
2
2
 
3
3
  phpを使って出勤、退勤、外出、戻りができるプログラムを書きたいのですがうまくいきません。
4
4
 

2

変更しました

2017/08/22 08:16

投稿

nrnrdsa
nrnrdsa

スコア19

test CHANGED
File without changes
test CHANGED
@@ -28,7 +28,365 @@
28
28
 
29
29
 
30
30
 
31
+ ```<HTML>
32
+
33
+ <HEAD>
34
+
35
+ <TITLE></TITLE>
36
+
37
+ <STYLE type="text/css">
38
+
39
+ <!--
40
+
41
+ BODY {
42
+
43
+ background-image: url("gazou/haikei.jpg"); /* 全体の背景画像 */
44
+
45
+ background-repeat: no-repeat; /* 背景を繰り返さない */
46
+
47
+ background-position: 50% 50%; /* 背景画像の位置は画面中央 */
48
+
49
+ background-attachment:fixed; /* 背景画像を固定する */
50
+
51
+ background-size:2000px auto;
52
+
53
+ }
54
+
55
+ </STYLE>
56
+
57
+ </HEAD>
58
+
59
+ <BODY>
60
+
61
+ </BODY>
62
+
63
+ </HTML>
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+ <?php
74
+
75
+ ini_set('display_errors', 'On');
76
+
77
+ error_reporting(E_ALL);
78
+
79
+
80
+
81
+ $dsn = 'mysql:dbname=mfdb;host=localhost';
82
+
83
+ $user = 'root';
84
+
85
+ $password = '';
86
+
87
+ //日本語の曜日配列
88
+
89
+ $weekjp = array(
90
+
91
+ '日', //0
92
+
93
+ '月', //1
94
+
95
+ '火', //2
96
+
97
+ '水', //3
98
+
99
+ '木', //4
100
+
101
+ '金', //5
102
+
103
+ '土' //6
104
+
105
+ );
106
+
107
+
108
+
109
+ //現在の曜日番号(日:0 月:1 火:2 水:3 木:4 金:5 土:6)を取得
110
+
111
+ $weekno = date('w');
112
+
113
+
114
+
115
+
116
+
117
+ try {
118
+
119
+
120
+
121
+ if (filter_input_array(INPUT_POST)) {
122
+
123
+ $id = filter_input(INPUT_POST, 'id');//利用者ID
124
+
125
+ $first_name = filter_input(INPUT_POST, 'first_name');//利用者名
126
+
127
+ $startyear = filter_input(INPUT_POST, 'startyear');//今年度の開始年
128
+
129
+ $startmonth = filter_input(INPUT_POST, 'startmonth');//今年度の開始月
130
+
131
+ $startday = filter_input(INPUT_POST, 'startday');//今年度の開始日
132
+
133
+ $startweek = filter_input(INPUT_POST, 'startweek');//今年度の開始曜日
134
+
135
+ $startsituation = filter_input(INPUT_POST, 'startsituation');//勤怠内容
136
+
137
+ $field2 = filter_input(INPUT_POST, 'field2');//出勤時間
138
+
139
+
140
+
141
+ $err = array();//エラー内容
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+ // エラーの数を数えて、エラーがなければインサート
150
+
151
+ if (0 == count($err)) {
152
+
153
+ //DB連携とDB接続できなくばエラー
154
+
155
+ $db = new PDO($dsn, $user, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
156
+
157
+
158
+
159
+ if (isset($_POST["delete"])) {
160
+
161
+ $did = $_POST["delete"];
162
+
163
+ $qry = "DELETE FROM attendanse WHERE attendanceid =:did";
164
+
165
+ $stmt = $db->prepare($qry);
166
+
167
+ $stmt->execute();
168
+
169
+ }else if (isset($_POST["insert"])) {
170
+
171
+ $did = $_POST["insert"];
172
+
173
+ //attendanse(出勤用テーブル)を追加
174
+
175
+ $sql = "INSERT INTO attendanse (";
176
+
177
+ $sql .= "id, first_name, startyear, startmonth, startday, startweek,startsituation,field2 ";
178
+
179
+ $sql .= ") VALUES (";
180
+
181
+ $sql .= ":id,:first_name,:startyear,:startmonth,:startday,:startweek,:startsituation,:field2";
182
+
183
+ $sql .= ")";
184
+
185
+ $stmt = $db->prepare($sql);
186
+
187
+
188
+
189
+ // パラメータのセットの仕方はマニュアルで確認してください。
190
+
191
+ $stmt->bindParam(':id', $id, PDO::PARAM_STR);
192
+
193
+ $stmt->bindParam(':first_name', $first_name, PDO::PARAM_INT);
194
+
195
+ $stmt->bindParam(':startyear', $startyear, PDO::PARAM_STR);
196
+
197
+ $stmt->bindParam(':startmonth', $startmonth, PDO::PARAM_STR);
198
+
199
+ $stmt->bindParam(':startday', $startday, PDO::PARAM_STR);
200
+
201
+ $stmt->bindParam(':startweek', $startweek, PDO::PARAM_STR);
202
+
203
+ $stmt->bindParam(':startsituation', $startsituation, PDO::PARAM_STR);
204
+
205
+ $stmt->bindParam(':field2', $field2, PDO::PARAM_STR);
206
+
207
+ // 実行
208
+
209
+ $stmt->execute();
210
+
211
+ }
212
+
213
+
214
+
215
+ $qry = "SELECT * FROM attendanse";
216
+
217
+ $data = $db->query($qry);
218
+
219
+ $data->execute();
220
+
221
+ $rows = $data->fetchAll(PDO::FETCH_ASSOC);
222
+
223
+ //$registered = mysqli_affected_rows($db);
224
+
225
+ echo "<P>下記表の内容で登録しました</P>";
226
+
227
+ }
228
+
229
+ }else {
230
+
231
+ echo "<P>出勤時に必ず行って下さい</P>";
232
+
233
+ }
234
+
235
+ } catch (PDOException $e) {
236
+
237
+ $err['all'] = $e->getMessage();
238
+
239
+ }
240
+
241
+ ?>
242
+
243
+
244
+
245
+ <?php if (isset($err) && 0 < count($err)) : ?>
246
+
247
+ <p><?= nl2br(implode(PHP_EOL, $err)); ?></p>
248
+
249
+ <?php endif; ?>
250
+
251
+ <div class="example">
252
+
253
+ <form name="form1"action="Attendance.php" method="post">
254
+
255
+ <table>
256
+
257
+ <caption>勤怠登録手続き</caption>
258
+
259
+ <tr>
260
+
261
+ <th rowspan="2">従業員番号</th>
262
+
263
+ <th rowspan="2">名前</th>
264
+
265
+ <th colspan="4">日付</th>
266
+
267
+ <th rowspan="2">時間</th>
268
+
269
+ <th rowspan="2">出勤状況</th>
270
+
271
+ <th rowspan="2">登録内容</th>
272
+
273
+ </tr>
274
+
275
+ <tr>
276
+
277
+ <th>年</th>
278
+
279
+ <th>月</th>
280
+
281
+ <th>日</th>
282
+
283
+ <th>曜日</th>
284
+
285
+ </tr>
286
+
287
+ <tr>
288
+
289
+ <td><input type="text" name="id" size=" 10" maxlength="50" placeholder="○○太郎"
290
+
291
+ value="<?php if (isset($_POST['id'])) {echo htmlspecialchars($_POST['id'],ENT_QUOTES,"UTF-8");} ?>"></td>
292
+
293
+ <td><input type="text" name="first_name" size=" 10" maxlength="50" placeholder="○○太郎"
294
+
295
+ value="<?php if (isset($_POST['first_name'])) {echo htmlspecialchars($_POST['first_name'],ENT_QUOTES,"UTF-8");} ?>"></td>
296
+
297
+ <td><input type="text" name="startyear" size="1"value="<?php echo date("Y"); ?>" /></td>
298
+
299
+ <td><input type="text" name="startmonth" size="1"value="<?php echo date("m"); ?>" /></td>
300
+
301
+ <td><input type="text" name="startday" size="1"value="<?php echo date("d"); ?>" /></td>
302
+
303
+ <td><input type="text" name="startweek" size="1"value="<?php echo $weekjp[$weekno]; ?>"></td>
304
+
305
+ <td><input type="text" name="field2" size="9" value=""></td>
306
+
307
+ <td><select name="startsituation">
308
+
309
+ <option value="出 勤">出勤</option>
310
+
311
+ <option value="退 勤"退勤</option>
312
+
313
+ <option value="外 出">外出</option>
314
+
315
+ <option value="戻 り">戻り</option>
316
+
317
+ </select>
318
+
319
+ </td>
320
+
321
+ <td><input type="submit" value="出勤(in)" name="insert"></td>
322
+
323
+ </tr>
324
+
325
+ </table>
326
+
327
+ </div>
328
+
329
+ <hr><!-- //登録票と登録結果の区切り線?-->
330
+
331
+
332
+
333
+ <form action="Attendance.php" method="post">
334
+
335
+
336
+
337
+ <?php
338
+
339
+ //exitwork.php(退勤登録)の結果
340
+
341
+ //エラー設定
342
+
343
+ ini_set('display_errors', 'On');
344
+
345
+ error_reporting(E_ALL);
346
+
347
+ //DB接続設定
348
+
349
+
350
+
351
+ try {
352
+
353
+
354
+
355
+
356
+
357
+ echo "<div class='dbs'>
358
+
359
+ <table border>
360
+
361
+ <caption>出勤登録結果</caption>
362
+
363
+ <tbody>
364
+
365
+ <tr>
366
+
367
+ <th>編集</th>
368
+
369
+ <th>削除</th>
370
+
371
+ <th>出勤番号</th>
372
+
373
+ <th>会員番号</th>
374
+
375
+ <th>名前</th>
376
+
377
+ <th>出勤状況</th>
378
+
379
+ <th>日付</th>
380
+
381
+ <th>時間</th>
382
+
383
+ </tr>
384
+
385
+ <tr>";
386
+
387
+
388
+
31
- foreach ($rows as $row) {
389
+ foreach ($rows as $row) {
32
390
 
33
391
  echo "<td><a href='Attendancelist.php?attendanceid =".$row['attendanceid']."&=id".$row['id']."&first_name=".$row['first_name'].
34
392
 
@@ -84,9 +442,9 @@
84
442
 
85
443
  </form>
86
444
 
87
- ![イメジ説明](8164b8ade69bef5747dc180d8964fc85.png)
445
+
446
+
88
-
447
+ ```
89
-
90
448
 
91
449
  ###試したこと
92
450
 

1

foreach \(\$rows as \$row\) { echo "<td><a href='Attendancelist\.php\?attendanceid ="\.\$r

2017/08/22 08:08

投稿

nrnrdsa
nrnrdsa

スコア19

test CHANGED
File without changes
test CHANGED
@@ -28,7 +28,61 @@
28
28
 
29
29
 
30
30
 
31
+ foreach ($rows as $row) {
31
32
 
33
+ echo "<td><a href='Attendancelist.php?attendanceid =".$row['attendanceid']."&=id".$row['id']."&first_name=".$row['first_name'].
34
+
35
+ "&startyear=".$row['startyear']."&startmonth=".$row['startmonth']."&startday=".$row['startday']."&startweek=".$row['startweek'].
36
+
37
+ "&startsituation=".$row['startsituation']."&field2=".$row['field2']."'>編集</a></td>";
38
+
39
+ echo "<td><input type=\"radio\" name=\"delid\" value=\"{attendanceid}\"></td>";
40
+
41
+ echo "<td> ".$row['attendanceid']."</td>
42
+
43
+ <td> ".$row['id']."</td>
44
+
45
+ <td> ".$row['first_name']."</td>
46
+
47
+ <td> ".$row['startsituation']."</td>
48
+
49
+ <td> ".$row['startyear']."年".$row['startmonth']."月".$row['startday']."日(".$row['startweek'].")"."</td>
50
+
51
+ <td> ".$row['field2']."</td>
52
+
53
+ <tr>
54
+
55
+ </tr>";
56
+
57
+
58
+
59
+ }
60
+
61
+ echo "
62
+
63
+ </tbody>
64
+
65
+ </table>
66
+
67
+ </div>";
68
+
69
+ $db = null;
70
+
71
+ } catch (Exception $e) {
72
+
73
+ echo $e->getMessage();
74
+
75
+ }
76
+
77
+
78
+
79
+ ?><br>
80
+
81
+
82
+
83
+ <input type="submit" name="delete" value="削除">
84
+
85
+ </form>
32
86
 
33
87
  ![イメージ説明](8164b8ade69bef5747dc180d8964fc85.png)
34
88