I would like to know how I can do an update with checkbox
, with the system I developed I can get normal all checkbox
that will be changed but I can not get the id
from them how can I do this? below is the part of html
and that of php
HTML code
while($aux = mysqli_fetch_array($sql)){
$id = $aux['id'];
$nome = $aux['nome'];
$img = $aux['imgp'];
print"<div class=\"col-lg-3 col-md-4 col-sm-6 col-xs-12\">
<input type=\"hidden\" name=\"id\" value=\"$id\">
<div class=\"hovereffect\">
<span class=\"abcd\"></span>
<img id=\"he\" class=\"img-responsive\" src=\"../images/imagens/galeria/big/$img\" alt=\"$nome\">
<div class=\"overlay\">
<div class=\"btn-group\" data-toggle=\"buttons\">
<label class=\"btn btn-primary cke\">
<input type=\"checkbox\" name=\"ck[]\" value=\"nao\" id=\"$id\"><i class=\"fa fa-heart\"></i>
</label>
</div>
</div>
</div>
</div>";
}
PHP code
require "conexao.php";
if(isset($_POST["final"])){
foreach($_POST['ck'] as $ck){
$check = $ck;
$id = $_POST['id'];
$sql = mysqli_query($mysqli,"UPDATE galeria SET favorito = '$check' WHERE id = '$id'")or die(mysqli_error($mysqli));
}
if($sql)
echo "success";
else
echo "not success";
}
this code my code it works but always does the update in the last element, ex has 3 update I select the first and last it will only change the last one wanted it to change according to the id of the same someone could help me?