I have a number of rows with some checkboxes and I want for each row some value to be inserted into a table.
E.g. if the checkbox 'more_than_45min' is checked, the value 4 must be inserted into that row of that player, if the checkbox 'less_than_45min' is checked, the value 2 must be inserted into that row of that player.
The checkboxes can't be choose both but can be both empty (if a player hasn't played at all)
$query = "SELECT * FROM players WHERE club = 'AJA'";
if ($result = mysqli_query($conn, $query)) {
while ($row = mysqli_fetch_assoc($result)) {
$name = $row["name"];
$player_id = $row["player_id"];
echo "<div class='row pt-2'>";
echo "<div class='col-md-4'>" . $name . "</div>";
echo "<div class='col-md-1'><input class='custom-control-input' type='checkbox' data-speler-id=" . $player_id ." id='more_than_45min_" . $player_id ."'></div>";
echo "<div class='col-md-1'><input class='custom-control-input' type='checkbox' data-speler-id=" . $player_id ." id='less_than_45min_" . $player_id ."'></div>";
echo "</div>";
}
}
I have added an hidden field to check if the form has been submitted so I can insert the values into the table 'players_points', the fields in this table are:
- id (AI)
- player_id
- more_than_45min
- less_than_45min
Here's the start for the insert into the table.
if(isset($_POST['player_points_submit'])) {
// here the insert
}
I know how to insert the data into the table but how to loop through all the rows and submitted 4 or 2 into the table if a checkbox is checked?
Kind regards,
Arie
Aucun commentaire:
Enregistrer un commentaire