面對從MySQL 堡壘中清除多行的任務,您在編碼智慧的深處尋求啟蒙。在著手進行資料清理工作時,您似乎遇到了難以克服的障礙。
您所寫的程式碼雖然意圖勇敢,但未能執行其行消滅的預期目的。決心克服這個障礙,您通過向受人尊敬的編碼社區展示您的代碼來尋求指導:
<code class="html">// PHP witchcraft to connect to MySQL $dbc = mysqli_connect('localhost', 'root', 'admin', 'sample') or die('MySQL is out to get you!'); $query = "select * from links ORDER BY link_id"; $result = mysqli_query($dbc, $query) or die('Whoops! Query went awry!'); $count = mysqli_num_rows($result);</code>
<code class="html">// Assemble your army of checkboxes while ($row = mysqli_fetch_array($result)) { echo <<<HTML <tr> <td><input type="checkbox" name="checkbox[]" value="$row[link_id]"></td> <td>$row[link_id]</td> <td>$row[link_name]</td> <td>$row[link_url]</td> </tr> HTML; }</code>
<code class="html">// The arsenal of deletion awaits your command if (isset($_POST['delete'])) { // Retrieve your checked victims $checkbox = $_POST['checkbox']; // Summon the wrath of deletion upon each victim foreach ($checkbox as $del_id) { $sql = "DELETE FROM links WHERE link_id='$del_id'"; // Unleash the purging power! $result = mysqli_query($dbc, $sql); } // If successful, redirect to the crime scene if ($result) { echo '<meta http-equiv="refresh" content="0;URL=view_links.php">'; } }</code>
唉,您的程式碼因以下原因而不穩定一些關鍵的疏忽:
透過這些修正,您的程式碼將像數字魔法師一樣消除行。帶著新的信心開始您的資料清理任務!
以上是如何在 PHP 中使用複選框正確刪除多個資料庫行?的詳細內容。更多資訊請關注PHP中文網其他相關文章!