Hello, this is the first time that I have programmed in php and I have a problem that I have not been able to solve.
I can not get the data in a mysql column updated using a combobox with 2 elements.
and this is the code I have to make the update:
<?php
include_once 'conexion.php';
if(!empty($_POST)) {
$queryResult = $pdo->query('SELECT FROM ejj');
while ($row = $queryResult->fetch()) {
?>
<br><br>
<?php
var_dump($row);
}
$id = $_POST['id'];
$vigencia = $_POST['vigencia'];
$sql = "UPDATE ejj SET Vigencia=:vigencia where id=:id";
$query = $pdo->prepare($sql);
$query->execute([
'id' => $id,
'vigencia' => $vigencia
]);
$idValue = $id;
$vigenciaValue = $vigencia;
} else {
$id = $_GET['id'];
$sql= "SELECT * FROM ejj WHERE id=:id";
$query = $pdo->prepare($sql);
$query->execute([
'id'=>$id
]);
$row = $query->fetch(PDO::FETCH_ASSOC);
$idValue = $row['id'];
$vigenciaValue = $row['vigencia'];
}
?>
<br><br>
<?php
echo 'Se realizo una modificación';
?>
and the code in the table is:
<form action="modificar.php" method="post">
<table>
<h1>Trabajadores vigentes</h1>
<th>ID</th>
<th>Nombre</th>
<th>Apellido</th>
<th>vigentes</th>
<?php
$queryResult = $pdo->query('SELECT * FROM ejj');
while($row = $queryResult->fetch(PDO::FETCH_ASSOC)){;
?>
<tr>
<td><?php echo $row['id']?></td>
<td><?php echo $row['nombre']?></td>
<td><?php echo $row['apellido']?></td>
<td><select name="vigencia" value<?php echo $cboValue?> >
<option value="1">Vigente</option>
<option value="0">No vigente</option>
</select></td>
</tr>
<?php }; ?>
<th><input type="submit" name="BtnModificar" value="Modificar"/></th>
<input type="hidden" name="id" value="<?php echo $id?>">
</table>
<a href="agregar.php"><br>Agregar trabajadores</a>
</form>
</body>