国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

So l?schen Sie Zeilen mithilfe von Kontrollk?stchen in PHP und MySQL
P粉982009874
P粉982009874 2023-09-01 22:02:23
0
1
687
<p>Ich habe eine Tabelle mit den Datenbankinformationen erstellt und versucht, Kontrollk?stchen zu erstellen, um Zeilen einfacher l?schen zu k?nnen, aber etwas funktioniert nicht. </p> <p>Ich habe eine Schaltfl?che mit einem Formular: </p> <pre class="brush:php;toolbar:false;"><form action="delete-register.php" <button type="button" class="btn btn-primary"><span class="fe fe-file-plus fe-12 mr-2"></span>Neu</ Schaltfl?che> <button type="submit" name="delete" class="btn btn-secondary"><span class="fe fe-trash fe-12 mr-2"</span> ;L?schen</button> </form></pre> <p>Ich habe Zeilen mit Kontrollk?stchen: </p> <pre class="brush:php;toolbar:false;"><form action="delete-register.php" <td> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" id=<?php echo $row['id'] ?>" value="<?php echo $row['id']; <label class="custom-control-label" for=<?php echo $row['id'] ?>"></label> </div> </td> </form></pre> <p>Auch delete-register.php: </p> <pre class="brush:php;toolbar:false;">if (isset($_POST['delete'])) { if (isset($_POST['selected'])) { foreach ($_POST['selected'] as $id) { $query = "DELETE FROM registers WHERE id = $id"; mysqli_query($conn, $query); } header('Standort: registers.php'); Ausfahrt; } }</pre> <p>Das Problem besteht darin, dass ?selected“ immer leer ist, sodass nichts aus der Datenbank gel?scht wird. Wie kann ich dieses Problem l?sen? </p>
P粉982009874
P粉982009874

Antworte allen(1)
P粉006540600

Please note that the data submitted will be within the scope of <form>....</form>

由于您有兩個(gè)表單,當(dāng)您點(diǎn)擊第一個(gè)表單中的提交按鈕時(shí),它不會(huì)將第二個(gè)表單的數(shù)據(jù)發(fā)送到服務(wù)器。

因此,請將第二種形式更改為:

<form action="delete-register.php" method="post">

      <div class="custom-control custom-checkbox">
       <input type="checkbox" class="custom-control-input" id="<?php echo $row['id']; ?>" name="selected[]" value="<?php echo $row['id']; ?>">
       <label class="custom-control-label" for="<?php echo $row['id']; ?>"></label>
     </div>

<input type=submit name=delete>

</form>

[補(bǔ)充說明]

如果您想堅(jiān)持使用第一種形式來觸發(fā)刪除操作,那么請:

  1. 在第一種表單中,將刪除從“提交”更改為“按鈕”
  2. 向此刪除按鈕添加 onclick 事件,以便觸發(fā)第二個(gè)表單的提交
  3. 確保在第二種形式中有一個(gè)名為“delete”的隱藏字段,因?yàn)槟付ㄔ?PHP 腳本中包含此字段
  4. you may have noticed that I have added id=form2 in the 2nd form so as to facilitate triggering of the submission by form1

這是修改后的代碼:

<form method="post">
   <button type="button" class="btn btn-primary"><span class="fe fe-file-plus fe-12 mr-2"></span>New</button>

   <button type="button" name="delete" class="btn btn-secondary"
onclick='document.getElementById("form2").submit()';
   ><span class="fe fe-trash fe-12 mr-2"></span>Delete</button>

</form>



<form id=form2 action="delete-register.php" method="post">

   <div class="custom-control custom-checkbox">
       <input type="checkbox" class="custom-control-input" id="<?php echo $row['id']; ?>" name="selected[]" value="<?php echo $row['id']; ?>">
       <label class="custom-control-label" for="<?php echo $row['id']; ?>"></label>
     </div>

<input type=hidden name=delete value="delete">

</form>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage