Basically I want to insert into database the data according to input value. I have multiple checkbox and input field. When I store data only " A " then its working and others are null values. If I stored others with A then stored all the values. User can be check and input values any time and any number of check box. Here are the code snippet,
<form action="">
<input type="checkbox" name="txt_check[]" id="">A
<label for="fname">Win1:</label>
<input type="text" id="fname" name="txt_win[]"><br><br>
<label for="fname">Win2:</label>
<input type="text" id="fname" name="txt_loss[]"><br><br>
<label for="fname">Win3:</label>
<input type="text" id="fname" name="txt_draw[]"><br><br>
<input type="checkbox" name="txt_check[]" id="">B
<label for="lname">Loss1:</label>
<input type="text" id="fname" name="txt_win[]"><br><br>
<label for="lname">Loss2:</label>
<input type="text" id="fname" name="txt_loss[]"><br><br>
<label for="lname">Loss3:</label>
<input type="text" id="fname" name="txt_draw[]"><br><br>
<input type="checkbox" name="txt_check[]" id="">C
<label for="lname">Draw1:</label>
<input type="text" id="fname" name="txt_win[]"><br><br>
<label for="lname">Draw2:</label>
<input type="text" id="fname" name="txt_loss[]"><br><br>
<label for="lname">Draw3:</label>
<input type="text" id="fname" name="txt_draw[]"><br><br>
<input type="submit" value="Submit">
</form>
Here is the Controller:
$win = $request->txt_win;
$loss = $request->txt_loss;
$draw = $request->txt_draw;
$checkValue = $request->txt_check ;
foreach $checkValue as $key => $value) {
$result[] = Model::create([
'checkValue' => $value,
'winning' => $win [$key],
'lost' => $loss [$key],
'draw' => $draw [$key],
]);
}
This code works well for the first insert but when I try to second insert then insert null value like this-
I want to insert into database this way,
checkval win loss draw
A 2 3 4
B 3 4 3
C 4 5 5
How can I do this. I need help. Advanced thanks.