これはWHERE句の仕様ですか?
ユーザーから受け取った文字列を利用してカラムを埋め込むのはNGです
(管理画面や自分専用を除く)
また中身が空文字""のときにNULLと比較してしまうのでまったくだめです
そもそもNULLを検出する演算子は等号ではなくisです
sample
ちゃんとやるなら最低限こうしてください
PHP
1<?PHP
2$shift_flag=filter_input(INPUT_POST,"shift_flag");
3$is_null=filter_input(INPUT_POST,"is_null",FILTER_DEFAULT,FILTER_REQUIRE_ARRAY)?:[];
4$set="";
5$data=[];
6if(in_array("shift_flag",$is_null)){
7 $set.=",shift_flag = null";
8}elseif(!is_null($shift_flag)){
9 $set.=",shift_flag = ?";
10 $data[]=$shift_flag;
11}
12print $set."<br>";
13print_r($data);
14?>
15<script>
16window.addEventListener('DOMContentLoaded', function(e){
17 [].forEach.call(document.querySelectorAll('[name="is_null[]"]'),function(x){
18 x.addEventListener('change',function(e){
19 document.querySelector('[name="'+e.target.value+'"]').disabled=e.target.checked;
20 });
21 });
22});
23</script>
24<form method="post">
25シフトフラグ:<input type="text" name="shift_flag" value="0" id="shift_flag">
26<label><input type="checkbox" name="is_null[]" value="shift_flag">null</label><br>
27<input type="submit" value="send"></form>
さらにバリデートを厳密に適用するならこう
PHP
1<?PHP
2$shift_flag=filter_input(INPUT_POST,"shift_flag",FILTER_VALIDATE_INT);
3$is_null=filter_input(INPUT_POST,"is_null",FILTER_DEFAULT,FILTER_REQUIRE_ARRAY)?:[];
4$set="";
5$data=[];
6
7if(in_array("shift_flag",$is_null)){
8 $set.=",shift_flag = null";
9}elseif($shift_flag===false){
10 print "error";
11}elseif(!is_null($shift_flag)){
12 $set.=",shift_flag = ?";
13 $data[]=$shift_flag;
14}
15print $set."<br>";
16print_r($data);
17?>
18<script>
19window.addEventListener('DOMContentLoaded', function(e){
20 [].forEach.call(document.querySelectorAll('[name="is_null[]"]'),function(x){
21 x.addEventListener('change',function(e){
22 document.querySelector('[name="'+e.target.value+'"]').disabled=e.target.checked;
23 });
24 });
25});
26</script>
27<form method="post">
28シフトフラグ:<input type="text" name="shift_flag" value="0" id="shift_flag" pattern="\d+" required>
29<label><input type="checkbox" name="is_null[]" value="shift_flag">null</label><br>
30<input type="submit" value="send"></form>
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/03 01:47
2019/06/03 02:36
2019/06/03 03:21
2019/06/03 03:59
2019/06/03 04:05 編集
2019/06/03 05:24
2019/06/03 05:27
2019/06/03 05:53