I came across a situation I can not get around.
I need to update a MySQL database field where its display is a checkbox .
I'll try to exemplify:
A search brings up a series of records, where after I checkboxes and click the "Confirm Conference" button, all records listed on this page should be updated according to checkbox
checked, that is, only the checkbox field will be updated. Follow the image showing the screen that already exists.
Thecodeformypageisthis:
<html><body><divid="main" class="container-fluid">
<div id="top" class="row" style="margin-top: 50px">
<div class="col-sm-4">
<h3>Conferência do Depósito</h3>
</div>
</div> <!-- /#top -->
</br>
<div id="conf_deposito" class="row">
<div class="table-responsive col-md-12">
<table class="table table-striped table-bordered " width="100%" id="tabela_datatables">
<thead>
<tr>
<th>Conferir</th>
<th>Nome</th>
<th>Tombamento</th>
<th>Quantidade</th>
</tr>
</thead>
<tbody>
<?php
//Verifica se já existem registros com a mesma data do sistema. Se não existir, executa a cópia da tabela.
$sis_data = date("Y/m/d");
$unic = "SELECT * FROM conf_material WHERE data = '$sis_data'";
$unic = $pdo->query($unic);
if($unic->rowCount() < 1) {
//Ao carregar a página, executa uma cópia dos registros para conferência.
$cop = "INSERT INTO conf_material (nome, tombamento, quantidade, local) SELECT nome, tombamento, quantidade, local FROM lista_geral WHERE local = 'deposito'";
$cop = $pdo->query($cop);
//Atualiza o campo de data para o data do dia.
$atualiza_data = "UPDATE conf_material SET data = '$sis_data' WHERE data = '0000-00-00'";
$atualiza_data = $pdo->query($atualiza_data);
}
if(isset($_POST['nome']) && empty($_POST['nome']) == false) {
$nome = addslashes($_POST['nome']);
$tombamento = addslashes($_POST['tombamento']);
$quantidade = addslashes($_POST['quantidade']);
$conferir = addslashes($_POST['conferir']);
$sql = "UPDATE conf_material SET conferir = '$check_confirm'";
$pdo->query($sql);
}
$sql = "SELECT * FROM conf_material WHERE local = 'Deposito' AND data = '$sis_data'";
$sql = $pdo->query($sql);
if($sql->rowCount() > 0) {
foreach ($sql -> fetchAll() as $conf_deposito) { ?>
<tr>
<td class="actions">
<input type='checkbox' id="check_confirm" name="check_confirm" value="1" class='btn btn-success btn-xs' data- data-toggle="modal"></button></a>
</td>
<td><?php echo $conf_deposito['nome']; ?></td>
<td><?php echo $conf_deposito['tombamento']; ?></td>
<td><?php echo $conf_deposito['quantidade']; ?></td>
</tr>
<?php } ?> <!-- Fecha foreach -->
<?php } ?> <!-- Modal de IF rowcount -->
<form method="POST">
<div class="row">
<div class="form-group col-md-4">
<input type="submit" value="Confirmar Conferência" class="btn btn-primary" />
<a href="lista_geral.php" class="btn btn-default">Limpar</a>
</div>
</form>
</tbody>
</table>
<!-- Rodapé -->
<?php require "rodape.php"; ?>
</body>
</html>
Does anyone have any idea how I can do this?