初めて質問させていただきます。つたない部分等あるかと思いますがよろしくお願いいたします。
前提・実現したいこと
ある学校に通っていて、チームを作ってシステムを制作する課題になります。
学校の生徒の情報を管理するようなシステムを作成しています。
phpを使用していて、htmlのフォームでPOSTで値を送ってデータベースにインサートしていくようなものです。
発生している問題・エラーメッセージ
Notice: Undefined index: date in /var/www/html/health/health_use_register.php on line 42
このような文がたくさん出てしまっていて
フォームから送信→確認画面→登録しました という流れなんですが
確認画面に編集ボタンも実装していて、それを押すと初めのフォームに値をhidden でPOSTして送るみたいなことをしています。
POSTした時は上のエラーメッセージはでません。なので初めに送られてきてもないPOSTを受け取ろうとしているエラーなのかなと思っています。
あとどうしてもわからなかったのがradioボタンの値を編集ボタン押した後にPOSTでうけとれるのはわかるのですが、それをcheckedにして表示する方法を知りたいです。
なのでもっと効率がいい方法など調べてもわからなかったので教えていただきたいです。
### 該当のソースコード
health_use_register.php
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>保健室利用メモフォーム</title> </head> <body> <h3>保健室利用メモ</h3> <form action="health_use_register_check.php" method="post"> <?php $dsn = 'mysql:dbname=CareSupport;host=localhost;charset=utf8mb4'; $user = 'root'; $password = 'rootg10'; $date = $_POST['date']; $student_num = $_POST['student_num']; $student_name = $_POST['student_name']; $student_teacher = $_POST['student_teacher']; $symptom = $_POST['symptom']; $symptom_time = $_POST['symptom_time']; $symptom_cause = $_POST['symptom_cause']; $taiou = $_POST['taiou']; $symptom_fix = $_POST['symptom_fix']; $memo = $_POST['memo']; $symptom_type = $_POST['symptom_type']; $entry_time = $_POST['entry_time']; $exit_time = $_POST['exit_time']; $staff = $_POST['staff']; ?> <table> <tr> <th>日付:</th> <td><input type="date" id="today" name="date" value="<?php echo $date; ?>"></td> </tr> <tr> <th>入室時間:</th> <td><input type="time" id="time" name="entry_time"></td> </tr> <tr> <th>退出時間:</th> <td><input type="time" id="time" name="exit_time" value="<?php echo $exit_time; ?>"></td> </tr> <tr> <th>学籍番号:</th> <td><input type="text" name="student_num" value="<?php echo $student_num; ?>"></td> </tr> <tr> <th>氏名:</th> <td><input type="text" name="student_name" value="<?php echo $student_name; ?>"></td> </tr> <tr> <th>性別:</th> <td><input type="radio" name="gender" value="1">男 <input type="radio" name="gender" value="2">女 </td> </tr> <tr> <th>担任:</th> <td><input type="text" name="student_teacher" value="<?php echo $student_teacher; ?>"></td> </tr> <tr> <th>症状:</th> <td><input type="text" name="symptom" value="<?php echo $symptom; ?>"></td> </tr> <tr> <th>いつから:</th> <td><input type="text" name="symptom_time" value="<?php echo $symptom_time; ?>"></td> </tr> <tr> <th>原因は?:</th> <td><input type="text" name="symptom_cause"" value="<?php echo $symptom_cause; ?>"></td> </tr> <tr> <th>対応:</th> <td><input type="text" name="taiou" value="<?php echo $taiou; ?>"></td> </tr> <tr> <th>処置:</th> <td><input type="text" name="symptom_fix" value="<?php echo $symptom_fix ?>"></td> </tr> <tr> <th>症状種別:</th> <td> <input type="radio" name="symptom_type" value="外科">外科 <input type="radio" name="symptom_type" value="内科">内科 </tr> <tr> <th>メモ:</th> <td><textarea name="memo" value="<?php echo $memo; ?>"></textarea></td> </tr> <tr> <th>対応者:</th> <td><input type="text" name="staff" value="<?php echo $staff; ?>"></td> </tr> </table> <input type="submit" value="確定">
health_use_register_check.php
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>保健室利用メモ確認</title> </head> <body> <?php $date = $_POST['date']; $student_num = $_POST['student_num']; $student_name = $_POST['student_name']; $student_teacher = $_POST['student_teacher']; $symptom = $_POST['symptom']; $symptom_time = $_POST['symptom_time']; $symptom_cause = $_POST['symptom_cause']; $taiou = $_POST['taiou']; $symptom_fix = $_POST['symptom_fix']; $memo = $_POST['memo']; $symptom_type = $_POST['symptom_type']; $entry_time = $_POST['entry_time']; $exit_time = $_POST['exit_time']; $staff = $_POST['staff']; $gender = $_POST['gender']; ?> <table> <tr> <th>日付:</th> <td><?php echo $date; ?></td> </tr> <tr> <th>入室時間:</th> <td><?php echo $entry_time; ?></td> </tr> <tr> <th>退出時間:</th> <td><?php echo $exit_time; ?></td> </tr> <tr> <th>学籍番号:</th> <td><?php echo $student_num; ?></td> </tr> <tr> <th>氏名:</th> <td><?php echo $student_name; ?></td> </tr> <tr> <th>性別:</th> <td><?php echo $gender; ?></td> </tr> <tr> <th>担任:</th> <td><?php echo $student_teacher; ?></td> </tr> <tr> <th>症状:</th> <td><?php echo $symptom; ?></td> </tr> <tr> <th>いつから:</th> <td><?php echo $symptom_time; ?></td> </tr> <tr> <th>原因は?:</th> <td><?php echo $symptom_cause; ?></td> </tr> <tr> <th>対応:</th> <td><?php echo $taiou; ?></td> </tr> <tr> <th>処置:</th> <td><?php echo $symptom_fix; ?></td> </tr> <tr> <th>症状種別:</th> <td><?php echo $symptom_type; ?></td> </tr> <tr> <th>メモ:</th> <td><?php echo $memo; ?></textarea></td> </tr> <tr> <th>対応者:</th> <td><?php echo $staff; ?></td> </tr> </table> <p>こちらの内容で登録しますか?</p> <form action="health_use_register_insert.php" method="post"> <input type="hidden" id="today" name="date" value="<?php echo $date; ?>"> <input type="hidden" id="time" name="entry_time" value="<?php echo $entry_time; ?>"> <input type="hidden" name="exit_time" value="<?php echo $exit_time; ?>"> <input type="hidden" name="student_num" value="<?php echo $student_num; ?>"> <input type="hidden" name="student_name" value="<?php echo $student_name; ?>"> <input type="hidden" name="gender" value="1" value="<?php echo $gender; ?>"> <input type="hidden" name="student_teacher" value="<?php echo $student_teacher; ?>"> <input type="hidden" name="symptom" value="<?php echo $symptom; ?>"> <input type="hidden" name="symptom_time" value="<?php echo $symptom_time; ?>"> <input type="hidden" name="symptom_cause" value="<?php echo $symptom_cause; ?>"> <input type="hidden" name="taiou" value="<?php echo $taiou; ?>"> <input type="hidden" name="symptom_fix" value="<?php echo $symptom_fix ?>"> <input type="hidden" name="symptom_type" value="<?php echo $symptom_type; ?>"> <input type="hidden" name="memo" value="<?php echo $memo; ?>"> <input type="hidden" name="staff" value="<?php echo $staff; ?>"> <input type="submit" value="確定"> </form> <br> <form action="health_use_register.php" method="post"> <input type="hidden" id="today" name="date" value="<?php echo $date; ?>"> <input type="hidden" id="time" name="entry_time" value="<?php echo $entry_time; ?>"> <input type="hidden" name="exit_time" value="<?php echo $exit_time; ?>"> <input type="hidden" name="student_num" value="<?php echo $student_num; ?>"> <input type="hidden" name="student_name" value="<?php echo $student_name; ?>"> <input type="hidden" name="gender" value="1" value="<?php echo $gender; ?>"> <input type="hidden" name="student_teacher" value="<?php echo $student_teacher; ?>"> <input type="hidden" name="symptom" value="<?php echo $symptom; ?>"> <input type="hidden" name="symptom_time" value="<?php echo $symptom_time; ?>"> <input type="hidden" name="symptom_cause" value="<?php echo $symptom_cause; ?>"> <input type="hidden" name="taiou" value="<?php echo $taiou; ?>"> <input type="hidden" name="symptom_fix" value="<?php echo $symptom_fix ?>"> <input type="hidden" name="symptom_type" value="<?php echo $symptom_type; ?>"> <input type="hidden" name="memo" value="<?php echo $memo; ?>"> <input type="hidden" name="staff" value="<?php echo $staff; ?>"> <input type="submit" value="編集"> </form> </body> </html>回答3件
あなたの回答
tips
プレビュー