質問するログイン新規登録

回答編集履歴

1

参考

2024/02/24 01:23

投稿

yambejp
yambejp

スコア118268

answer CHANGED
@@ -46,4 +46,40 @@
46
46
  $stmt = $PDO->prepare($sql);
47
47
  $params=[$name,$score1,$score2,$score3,$score4];
48
48
  $stmt->execute($params);
49
- ```
49
+ ```
50
+
51
+ # 参考
52
+ scoreの番号を渡して受け取った側で判断
53
+ ```HTML
54
+ <style>
55
+ [name=n]{display:none}
56
+ [name=n]:checked ~ span{color:red}
57
+ </style>
58
+ <ul>
59
+ <li><label><input type="radio" name="n" value="1" form="f1" checked><span>リスト1</span></label></li>
60
+ <li><label><input type="radio" name="n" value="2" form="f1"><span>リスト2</span></label></li>
61
+ <li><label><input type="radio" name="n" value="3" form="f1"><span>リスト3</span></label></li>
62
+ <li><label><input type="radio" name="n" value="4" form="f1"><span>リスト4</span></label></li>
63
+ </ul>
64
+ <form action="send.php" method="post" id="f1">
65
+ <p>名前:<input id="input" type="text"name="name"></p>
66
+ <p>スコア:<input type="text" name="score"></p>
67
+ <p><input type="submit" value="登録" class="button"></p>
68
+ </form>
69
+ ```
70
+ send.php
71
+ ```PHP
72
+ <?PHP
73
+ $name=filter_input(INPUT_POST,"name");
74
+ $score=filter_input(INPUT_POST,"score",FILTER_VALIDATE_INT);
75
+ $n=filter_input(INPUT_POST,"n",FILTER_VALIDATE_INT);
76
+ if($n){
77
+ ${"score".$n}=$score;
78
+ }
79
+ $score1=$score1??NULL;
80
+ $score2=$score2??NULL;
81
+ $score3=$score3??NULL;
82
+ $score4=$score4??NULL;
83
+ var_dump([$name,$score1,$score2,$score3,$score4]);
84
+ ```
85
+ DBへの投入は次のレベルなので割愛