title: How to delete multiple rows from mysql database with checkbox using PHP?
body: <p>I try to <code>delete</code> my data in "admin" database, but the delete button does not function.</p>
  
  <p>This is my top part</p>
  
  <pre><code>&lt;?php
  $host="localhost"; // Host name 
  $username="root"; // Mysql username 
  $password=""; // Mysql password 
  $db_name="admin"; // Database name 
  $tbl_name="admin"; // Table name 
  // Connect to server and select databse.
  mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
  mysql_select_db("$db_name")or die("cannot select DB");
  $sql="SELECT * FROM $tbl_name";
  $result=mysql_query($sql);
  $count=mysql_num_rows($result);
  ?&gt;
  </code></pre>
  
  <p>This is my checkbox code</p>
  
  <pre><code>&lt;tbody&gt;
  &lt;?php
      while($rows=mysql_fetch_array($result)){
  ?&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;?php echo $rows['course_code']; ?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;?php echo $rows['course_name']; ?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;?php echo $rows['lecture_id']; ?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input name="checkbox[]" type="checkbox"
      id="checkbox[]" value="&lt;?php echo $rows['course_code'];?&gt;"&gt;&lt;/td&gt;
  &lt;td&gt;&lt;form&gt;
  &lt;/form&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;?php
      }
  ?&gt;
  &lt;/tbody&gt;
  </code></pre>
  
  <p>and, this is my button code</p>
  
  <pre><code>&lt;input type='button' id="delete" value='Delete' name='delete'&gt;
  </code></pre>
  
  <p>This is my php function code</p>
  
  <pre><code>&lt;?php
  if(isset($_POST['delete'])){
  for($i=0;$i&lt;$count;$i++){
  $del_id = $checkbox[$i];
  $sql = "DELETE FROM $tbl_name WHERE course_code='$del_id'";
  $result = mysql_query($sql);
  }
  if($result){
  echo "&lt;meta http-equiv=\"refresh\" content=\"0;URL=delete.php\"&gt;";
  }
  }
  mysql_close();
  ?&gt;
  </code></pre>