0
I came across a situation I’m not getting around.
I need to update a field in Mysql database, where its display is a checkbox.
I will try to exemplify:
A search brings a series of records, where, after I mark the checkbox and click the button "Confirm Conference", all records listed on this page must be updated according to the checkbox
marked, that is, only the checkbox field will be updated. Follow image showing the screen that already exists.
The code on my page is this:
<html>
<body>
<div id="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 do it?
1 - checkbox are out of form - 2 inputs have value = 1 always? 3 - In the name attribute, at the end of your name, you must place brackets, indicating that more than one value can be sent to the same field. on the server side, an array of these elements will be sent. 4 - Missing action in the form (send to the current page)
– user60252