यहां, इसका परीक्षण किया गया है और mysqli_
. का उपयोग करते हुए काम कर रहा है mysql_
. के बजाय
अपने स्वयं के क्रेडेंशियल से बदलें।
कुछ चीजें, आपके चेकबॉक्स को नामित तत्व के चारों ओर वर्ग कोष्ठक की आवश्यकता है जैसा कि मैंने अपनी टिप्पणी में उल्लेख किया है, अर्थात name='checkbox[]'
अन्यथा आपको एक अमान्य foreach
प्राप्त होगा तर्क त्रुटि।
सिडेनोट:कुछ स्वरूपण करने के लिए खड़ा है, लेकिन यह काम करता है।
<table class="ts">
<tr>
<th class="tg-031e" style='width:1px'>ID</th>
<th class="tg-031e">IP address</th>
<th class="tg-031e">Date added</th>
<th class="tg-031e">Reason</th>
</tr>
<?php
$DB_HOST = "xxx";
$DB_NAME = "xxx";
$DB_USER = "xxx";
$DB_PASS = "xxx";
$con = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
if($con->connect_errno > 0) {
die('Connection failed [' . $con->connect_error . ']');
}
$SQL = "SELECT `ID`, `IPaddress`, `DateAdded`, `Reason` FROM `banned`";
$exec = mysqli_query($con,$SQL);
echo "<form method='post'>";
while ($row = mysqli_fetch_array($exec)){
echo "<tr class='tg-031h'>";
echo "<td class='tg-031e'><input type='checkbox' name='checkbox[]' value='" . $row[ID] . "'></td>";
echo "<td class='tg-031e'>" . $row['IPaddress'] . "</td>";
echo "<td class='tg-031e'>" . $row['DateAdded'] . "</td>";
echo "<td class='tg-031e'>" . $row['Reason'] . "</td>";
}
echo "</tr></table>";
echo "<input name='delete' type='submit' value='Delete'></form>";
if (isset($_POST['delete']) && isset($_POST['checkbox'])) {
foreach($_POST['checkbox'] as $id){
$id = (int)$id;
$delete = "DELETE FROM banned WHERE ID = $id";
mysqli_query($con,$delete);
}
}
?>
mysqli_*
तैयार बयानों के साथ
, या पीडीओ
तैयार किए गए स्टेटमेंट के साथ
इसके लिए।
संपादित करें: mysql_
संस्करण
<table class="ts">
<tr>
<th class="tg-031e" style='width:1px'>ID</th>
<th class="tg-031e">IP address</th>
<th class="tg-031e">Date added</th>
<th class="tg-031e">Reason</th>
</tr>
<?php
include 'connect.php';
$SQL = "SELECT `ID`, `IPaddress`, `DateAdded`, `Reason` FROM `banned`";
$exec = mysql_query($SQL, $connection);
echo "<form method='post'>";
while ($row = mysql_fetch_array($exec)){
echo "<tr class='tg-031h'>";
echo "<td class='tg-031e'><input type='checkbox' name='checkbox[]' value='" . $row[ID] . "'></td>";
echo "<td class='tg-031e'>" . $row['IPaddress'] . "</td>";
echo "<td class='tg-031e'>" . $row['DateAdded'] . "</td>";
echo "<td class='tg-031e'>" . $row['Reason'] . "</td>";
}
echo "</tr></table>";
echo "<input name='delete' type='submit' value='Delete'></form>";
if (isset($_POST['delete']) && isset($_POST['checkbox'])) {
foreach($_POST['checkbox'] as $id){
$id = (int)$id;
$delete = "DELETE FROM banned WHERE ID = $id";
mysql_query($delete);
}
}
?>