lundi 29 novembre 2021

Update depending on checkbox if it's check or not it's not working for me

please I am new in php and as you can see in picture I have this table filled from a database called produit in mysql, I want when I checked one of the checkbox or tow or all of them enabled date columns and edited and when I click in button enregistrer do update. I tried a lot of codes and it's not working for me.

enter image description here

$query = "select * from produit where  Id_Projet = " . $_SESSION["SSidProjet"] . "";

$query_run = mysqli_query($link, $query);

echo '<form id="form1" method="post">';
echo '<table id="dataTable" class="table table-bordered">';
echo "<thead>";
echo "<tr>";
echo '<th><input type="checkbox" id="selectall" /></th>';
echo "<th>Numéro Produit</th>";
echo "<th>Dénomination</th>";
echo "<th>Superficie</th>";
echo "<th>Titre Foncier</th>";
echo "<th>Date Reception Administratif</th>";
echo "<th>Date Contrat</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";

if($query_run)
{
    while($row = mysqli_fetch_array($query_run)){
        echo "<tr>";
        echo '<td><input type="checkbox" value="' . $row['Id_Produit'] . '" name="TcheckBox[]" /></td>';
        echo '<td>' . $row['Num_Produit'] . '</td>';
        echo "<td>" . $row['Libelle_Produit'] . "</td>";
        echo "<td>" . $row['Superficie_Produit'] . " </td>";
        echo "<td>" . $row['Titre_Foncier_Produit'] . " </td>";
        echo "<td><input id=\"DateRA\" type=\"date\" value=" . $row['Date_Reception_Administratif_Temp'] . " readonly=\"readonly\" disabled ></td>";
        echo "<td><input id=\"DateC\" type=\"date\" value=" . $row['Date_Contrat_Temp'] . " readonly=\"readonly\" disabled ></td>";
        echo "</tr>";
    }
}

echo "</tbody>";                            
echo "</table>";
echo '<input type="submit" name="enregistrer" value="Enregistrer" />';
echo "</form>";

if(isset($_POST['enregistrer'])){
    $q="update produit set Date_Contrat_Temp='2021/12/01' where Id_Produit=";
    for ($i=0; $i<count($checkBox); $i++)
        $q .= "".$checkBox[$i]."";
    mysqli_query($q) or die (mysqli_error() );



Aucun commentaire:

Enregistrer un commentaire