Deleting Multiple Records using Checkboxes in PHP
<p>I am having an issue where I need to be able to delete multiple records using checkboxes.</p>

<p>Here is the code that I currently have.</p>

<pre><code>&lt;?php 
$host       = "localhost";
$user       = "root";
$pass       = "";
$dbName     = "ticket_history";
$table_name = "ticket_history";

################ Connect to the Database and SELECT DATA ####################################
$conn = mysql_connect($host, $user, $pass) or die ("Unable to connect");
mysql_select_db($dbName);
$query = "SELECT Date,Ticket_Number,Description,Result FROM $table_name";
$result = mysql_query($query);
$count=mysql_num_rows($result);
#############################################################################################
?&gt;
&lt;HTML&gt;
&lt;HEAD&gt;
&lt;TITLE&gt;&lt;/TITLE&gt;
&lt;/HEAD&gt;
&lt;BODY&gt;
&lt;table width=50%&gt;
    &lt;form method="post" action="insert_ticket.php"&gt;
        &lt;table width border='0'&gt;
            &lt;tr&gt;&lt;td&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Date:&lt;input type="text" name="date"/&gt;&lt;/td&gt;
            &lt;td&gt;Ticket #:&lt;input type="text" name="ticket"/&gt;&lt;/td&gt;&lt;/tr&gt;
            &lt;table&gt;
                &lt;tr&gt;&lt;td&gt;Description:&lt;TEXTAREA COLS=50 name="description"&gt;&lt;/TEXTAREA&gt;&lt;/td&gt;&lt;/tr&gt;
                &lt;tr&gt;&lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Result     :&lt;TEXTAREA COLS=50 name="result"&gt;&lt;/TEXTAREA&gt;&lt;/td&gt;&lt;/tr&gt;
            &lt;tr&gt;&lt;td&gt;&lt;input type="submit" name="submit" value="Add"/&gt;&lt;/td&gt;&lt;/tr&gt;
            &lt;/table&gt;
        &lt;/table&gt;
    &lt;/form&gt;
    &lt;form method="post" action="delete_ticket.php"&gt;
    &lt;input type="submit" name="delete" value="Delete"/&gt;
    &lt;/form&gt;
&lt;/table&gt;

&lt;?php
print "&lt;table width=80% border=1&gt;\n"; 
$cols = 0; 
while ($get_info = mysql_fetch_assoc($result)){ 
$id = $get_info-&gt;id;
if($cols == 0) 
{ 
  $cols = 1; 
  print "&lt;tr&gt;";
  print "&lt;th&gt;Select&lt;/th&gt;";  
  foreach($get_info as $col =&gt; $value) 
  { 

    print "&lt;th&gt;$col&lt;/th&gt;"; 
  } 
  print "&lt;tr&gt;\n"; 
} 
print "&lt;tr&gt;\n"; 
print "&lt;td&gt;&lt;input type='checkbox' name='selected[]' id='checkbox[]' value=$id&gt;&lt;/td&gt;";
foreach ($get_info as $field) 
print "\t&lt;td align='center'&gt;&lt;font face=arial size=1/&gt;$field&lt;/font&gt;&lt;/td&gt;\n"; 
print "&lt;/tr&gt;\n"; 
} 
print "&lt;/table&gt;\n"; 
mysql_close();
?&gt;

&lt;!------------------------------------------------------------!&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;

Delete.php
&lt;?php
$host       = "localhost";
$user       = "root";
$pass       = "";
$dbName     = "ticket_history";
$table_name = "ticket_history";

################ Connect to the Database and SELECT DATA ####################################
$conn = mysql_connect($host, $user, $pass) or die ("Unable to connect");
mysql_select_db($dbName);
$query = "SELECT Date,Ticket_Number,Description,Result FROM $table_name";
$result = mysql_query($query);
$count=mysql_num_rows($result);
#####################################


if($_POST['delete']) {
    $checkbox = $_POST['selected'];
    $countCheck = count($_POST['selected']);

    for($i=0;$i&lt;$countCheck;$i++) {
        $del_id = $checkbox[$i];

    $sql = "DELETE FROM ticket_history WHERE Auto = $del_id";
    $result = mysql_query($sql);
    }
}
?&gt;
</code></pre>

<p>I just want to be able to delete rows checked.  How would I go about doing this effectively and efficiently?</p>

<p>Thank you in advance.</p>
