Insert the values of an HTML table into a table in the BD

0

I have the following table: I would like the following values to be entered in the BD:

Employee, Employee Name, Date and finally the option that is selected from the 7 available.

At the moment the source code I have is the following:

    <?php

include 'conexio.php';

$asistencia="A";
$retardo="R";
$retardojus="RJ";
$falta="F";
$faltajus="FJ";
$incapacidad="I";
$cambio="CC";

/*
$sql = "SELECT * FROM usuarios";
$rs = $conn->query($sql);
*/

$sql2 = $conn->query("SELECT COUNT(*) FROM usuarios");
$total=$sql2->fetchColumn();

//echo $total;

$actual=date("d-m-Y");

$sql = $conn->prepare("SELECT * FROM usuarios");
$sql->execute();
$rs = $sql->fetchAll();

include 'views/asistencia.view.php';

?>

    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="css/styles.css">
    <title>Document</title>
</head>
<body>
    <table class="mitabla">
        <tr>
            <th># Empleado</th>
            <th>Nombre de Empleado</th>
            <th>Fecha</th>
            <th>Asistencia</th>
            <th>Retardo</th>
            <th>Retardo Justificado</th>
            <th>Falta</th>
            <th>Falta Justificada</th>
            <th>Incapacidad</th>
            <th>Cambio de Campaña</th>
        <?php foreach ($rs as $resultado): ?>
        <?php $nameRadio="r".$resultado["IdTrabajador"];
              $idRadio="r".$resultado["IdTrabajador"]; ?>
        <tr>
            <td><?php echo $resultado['IdTrabajador']; ?></td>
            <td><?php echo $resultado['Nombre']; ?></td>
            <td><label for="<?php echo $actual ?>" name="<?php echo $actual ?>"><?php echo $actual ?></label></td>
            <td><?php echo $asistencia ?><input type="radio" name="<?php echo $nameRadio; ?>" id=""></td>
            <td><?php echo $retardo ?><input type="radio" name="<?php echo $nameRadio; ?>" id=""></td>
            <td><?php echo $retardojus ?><input type="radio" name="<?php echo $nameRadio; ?>" id=""></td>
            <td><?php echo $falta ?><input type="radio" name="<?php echo $nameRadio; ?>" id=""></td>
            <td><?php echo $faltajus ?><input type="radio" name="<?php echo $nameRadio; ?>" id=""></td>
            <td><?php echo $incapacidad ?><input type="radio" name="<?php echo $nameRadio; ?>" id=""></td>
            <td><?php echo $cambio ?><input type="radio" name="<?php echo $nameRadio; ?>" id=""></td>
        </tr>
        <?php endforeach; ?>
    </table>
    <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
        <input type="submit" value="Registrar">
    </form>
</body>
</html>

I already managed to insert in the BD with the following:

$sql3 = $conn->prepare("INSERT INTO asistencia(Fecha, Simbolo, IdTrabajador) VALUES
                        (:fecha, :simbolo, :idtrabajador)");
$sql3->execute(array(':fecha'=>$actual,
                     ':simbolo'=>$falta,
                     ':idtrabajador'=>$resultado['IdTrabajador'])); 

The problem is that in the placeholder of: symbol I always pass the same variable and I would like it to be inserted according to the selected value.

Could you help me? Thank you very much.

    
asked by Guillermo Ricardo Spindola Bri 26.05.2017 в 20:22
source

0 answers