insérer requête sql sur bouton afin de modifié la bdd

Eléphanteau du PHP | 23 Messages

27 avr. 2017, 13:37

après de nombreuse tentative, j'ai rajouter $_post['Select'] mais je sais pas si je l'ai bien placé
voici le code
<?php
    //PHP avant tout
    if (!empty($_POST)) {
        //la connexion
        $connect = mysqli_connect("localhost", "root", "Mm101010", "smartphone");
         
        //la requete de recherche
        $query = "Select * from vu_affect_empl ";
        if (!empty($_POST["query"])) {
            $search = mysqli_real_escape_string($connect, $_POST["query"]);
            $query .= "WHERE USER_ID LIKE '";
            $query .= $search;
            $query .= "%' OR  USER_ID LIKE '";
            $query .= $search;
            $query .= "%' OR  Num_SIM LIKE '";
            $query .= $search;
            $query .= "%' ORDER BY Nom asc";
        } else {
            $query .= "ORDER BY USER_ID";
        }
        //Lancement de la requete
        $result = mysqli_query($connect, $query);
    }
 
?>
<!DOCTYPE html>
<htmls'
<head>
  <meta charset="utf-8"/>
<script>
    $_post['Select']
</script>
</head>
<body>
<?php
  if(isset($result) && mysqli_num_rows($result) > 0) {
?>
    <div class="table-responsive">
        <table class="table table bordered">
            <tr onclick="SelectLigne(this)">
                <td>&nbsp;</td>
                <th>USER ID</th>
                <th>Nom</th>
                <th>Prenom</th>
                <th>Num SIM</th>
                <th>PIN Terminal</th>
                <th>PIN SIM</th>
                <th>Num EMEI</th>
                <th>Date Debut</th>
                <th>Date Fin</th>
                <th>Vitre</th>
                <th>Coque</th>
                <th>Support Vehicule</th>
                <th>Actif</th>
                <th>Or Affectation1</th>
                <th>Statut</th>
            </tr>
<?php 
            while($row = mysqli_fetch_array($result)) {
?>
            <tr id="selecte">
                <td><input type="checkbox" onchange="changeValueOfCheckbox(this)"  name="Select[]" value="<?php echo $row['USER_ID'];?>" class="Selection"> </td>
                <td><?php echo $row["USER_ID"]; ?></td>
                <td><?php echo $row["Nom"]; ?></td>
                <td><?php echo $row["Prenom"]; ?></td>
                <td><?php echo $row["Num_SIM"]; ?></td>
                <td><?php echo $row["PIN_Terminal"]; ?></td>
                <td><?php echo $row["PIN_SIM"]; ?></td>
                <td><?php echo $row["Num_IMEI"]; ?></td>
                <td><?php echo $row["Date_Debut"]; ?></td>
                <td><?php echo $row["Date_Fin"]; ?></td>
                <td><?php echo $row["Vitre"]; ?></td>
                <td><?php echo $row["Coque"]; ?></td>
                <td><?php echo $row["Support_Vehicule"]; ?></td>
                <td><?php echo $row["Actif"]; ?></td>
                <td><?php echo $row["Or_Affectation1"]; ?></td>
                <td><?php echo $row["Statut"]; ?></td>
            </tr>
<?php
           } } else { echo 'Pas enregistrement pour le moment'; }
?>
<script>
    function changeValueOfCheckbox(check) {
      var tr = document.getElementById(check.value);
      var cssClass = tr.getAttribute('class');
      if (cssClass === null) {
        cssClass = '';
      }
      if (check.checked) {
        // add class selected
        cssClass += ' selecte';
      } else {
        // suppression class selected
        var sel = ' selecte';
        var i = cssClass.indexOf(sel);
        if (i > -1) {
          var tmp = cssClass.substring(0, i);
          tmp += cssClass.substring(i + sel.length);
          cssClass = tmp;
        }
      }
      tr.setAttribute('class', cssClass);
    }
</script>
</body>
merci

Avatar du membre
Modérateur PHPfrance
Modérateur PHPfrance | 8758 Messages

27 avr. 2017, 14:31

code inutile :
<script>
$_post['Select']
</script>

de plus $_post n'existe pas (par défaut) c'est $_POST la casse des caractères est importante.
je ne parle pas du problème de syntaxe html sur le tag html (ah ben si en fait ;) ).
<?php
    //PHP avant tout
    if (!empty($_POST)) {
        //la connexion
        $connect = mysqli_connect("localhost", "root", "Mm101010", "smartphone");
         
        //la requete de recherche
        $query = "Select * from vu_affect_empl ";
        if (!empty($_POST["query"])) {
            $search = mysqli_real_escape_string($connect, $_POST["query"]);
            $query .= "WHERE USER_ID LIKE '";
            $query .= $search;
            $query .= "%' OR  USER_ID LIKE '";
            $query .= $search;
            $query .= "%' OR  Num_SIM LIKE '";
            $query .= $search;
            $query .= "%' ORDER BY Nom asc";
        } else {
            $query .= "ORDER BY USER_ID";
        }
        //Lancement de la requete
        $result = mysqli_query($connect, $query);
    }
 
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8"/>
  <style type="text/css">
    .selected > td {
      background-color : pink;
      font-weight : bold;
    }
  </style>
  <script type="text/javascript">
      function changeValueOfCheckbox(check) {
        var tr = document.getElementById(check.value);
        var cssClass = tr.getAttribute('class');
        if (cssClass === null) {
          cssClass = '';
        }
        if (check.checked) {
          // add class selected
          cssClass += ' selecte';
        } else {
          // suppression class selected
          var sel = ' selecte';
          var i = cssClass.indexOf(sel);
          if (i > -1) {
            var tmp = cssClass.substring(0, i);
            tmp += cssClass.substring(i + sel.length);
            cssClass = tmp;
          }
        }
        tr.setAttribute('class', cssClass);
      }
  </script>
</head>
<body>
<?php
  if(isset($result) && mysqli_num_rows($result) > 0) {
?>
    <div class="table-responsive">
        <table class="table table bordered">
          <thead>
            <tr>
                <th>&nbsp;</td>
                <th>USER ID</th>
                <th>Nom</th>
                <th>Prenom</th>
                <th>Num SIM</th>
                <th>PIN Terminal</th>
                <th>PIN SIM</th>
                <th>Num EMEI</th>
                <th>Date Debut</th>
                <th>Date Fin</th>
                <th>Vitre</th>
                <th>Coque</th>
                <th>Support Vehicule</th>
                <th>Actif</th>
                <th>Or Affectation1</th>
                <th>Statut</th>
            </tr>
          </thead>
          <tbody>
<?php 
            while($row = mysqli_fetch_array($result)) {
?>
            <tr id="<?= $row["USER_ID"] ?>">
                <td><input type="checkbox" onchange="changeValueOfCheckbox(<?= $row["USER_ID"] ?>)"  name="Select[]" value="<?php echo $row['USER_ID'];?>" class="Selection"> </td>
                <td><?php echo $row["USER_ID"]; ?></td>
                <td><?php echo $row["Nom"]; ?></td>
                <td><?php echo $row["Prenom"]; ?></td>
                <td><?php echo $row["Num_SIM"]; ?></td>
                <td><?php echo $row["PIN_Terminal"]; ?></td>
                <td><?php echo $row["PIN_SIM"]; ?></td>
                <td><?php echo $row["Num_IMEI"]; ?></td>
                <td><?php echo $row["Date_Debut"]; ?></td>
                <td><?php echo $row["Date_Fin"]; ?></td>
                <td><?php echo $row["Vitre"]; ?></td>
                <td><?php echo $row["Coque"]; ?></td>
                <td><?php echo $row["Support_Vehicule"]; ?></td>
                <td><?php echo $row["Actif"]; ?></td>
                <td><?php echo $row["Or_Affectation1"]; ?></td>
                <td><?php echo $row["Statut"]; ?></td>
            </tr>
<?php
           }
           echo '</tbody></table>';
         } else { echo 'Pas enregistrement pour le moment'; }
?>
</body>
</html>
<?php 
mysqli_free_result($result);
mysqli_close($connect);
@+
Il en faut peu pour être heureux ......