title: Cannot fix the select/delete function. PHP/MySQL/JavaScript
body: <p>guys I have the following script for adding, editing and deleting content in mysql, and showing it at index.php file. So here is my index.php file:</p>
  
  <pre><code>&lt;script&gt;function goDel() 
  { 
      var recslen =  document.forms[0].length; 
      var checkboxes="" 
      for(i=1;i&lt;recslen;i++) 
      { 
          if(document.forms[0].elements[i].checked==true) 
          checkboxes+= " " + document.forms[0].elements[i].name 
      } 
  
      if(checkboxes.length&gt;0) 
      { 
          var con=confirm("Are you sure you want to delete"); 
          if(con) 
          { 
              document.forms[0].action="delete.php?recsno="+checkboxes 
              document.forms[0].submit() 
          } 
      } 
      else 
      { 
          alert("No record is selected.") 
      } 
  } 
  
  function selectall() 
  { 
  //        var formname=document.getElementById(formname); 
  
          var recslen = document.forms[0].length; 
  
          if(document.forms[0].topcheckbox.checked==true) 
              { 
                  for(i=1;i&lt;recslen;i++) { 
                  document.forms[0].elements[i].checked=true; 
                  } 
      } 
      else 
      { 
          for(i=1;i&lt;recslen;i++) 
          document.forms[0].elements[i].checked=false; 
      } 
  } 
  &lt;/script&gt;
  &lt;style type="text/css"&gt; 
  &lt;!-- 
  .style1 {color: #FFFFFF} 
  --&gt; 
  &lt;/style&gt; 
  &lt;/head&gt; 
  
  &lt;body&gt; 
  &lt;table width="775" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"&gt; 
    &lt;tr&gt; 
      &lt;td&gt;&lt;hr size="1" noshade&gt;&lt;/td&gt; 
    &lt;/tr&gt; 
    &lt;tr&gt; 
      &lt;td&gt; 
        &lt;form action="" method="post" name="" id=""&gt; 
          &lt;table width="600" border="1" align="center" cellpadding="2" cellspacing="2"&gt; 
            &lt;tr&gt; 
              &lt;td&gt;&lt;input name="topcheckbox" type="checkbox" class="check" id="topcheckbox" onClick="selectall();" value="ON"&gt; 
  Select All    &lt;/td&gt; 
              &lt;td colspan="3" align="center"&gt;&lt;a href="form.php?mode=add"&gt;Add New Branch &lt;/a&gt;&lt;/td&gt; 
            &lt;/tr&gt; 
            &lt;tr&gt; 
              &lt;td&gt;&lt;strong&gt;&lt;a href="javascript:goDel()"&gt;Delete&lt;/a&gt;&lt;/strong&gt;&lt;/td&gt; 
              &lt;td&gt;&lt;strong&gt;Branch Name &lt;/strong&gt;&lt;/td&gt; 
              &lt;td&gt;&lt;strong&gt;Short Name &lt;/strong&gt;&lt;/td&gt; 
              &lt;td&gt;&lt;strong&gt;Update&lt;/strong&gt;&lt;/td&gt; 
            &lt;/tr&gt; 
            &lt;? 
            include("conn.php"); 
            $sql="select sn,branchname,shortname from $branch order by sn"; 
            $result=mysql_query($sql,$connection) or die(mysql_error()); 
            while($row=mysql_fetch_array($result)) { 
            ?&gt; 
            &lt;tr&gt; 
              &lt;td&gt;&lt;input name="&lt;? echo $row['sn']; ?&gt;" type="checkbox" class="check"&gt;&lt;/td&gt; 
              &lt;td&gt;&lt;? echo $row['branchname']; ?&gt;&lt;/td&gt; 
              &lt;td&gt;&lt;? echo $row['shortname']; ?&gt;&lt;/td&gt; 
              &lt;td&gt;&lt;a href="&lt;? echo "form.php?sn=".$row['sn']."&amp;mode=update"; ?&gt;"&gt;Update&lt;/a&gt;&lt;/td&gt; 
            &lt;/tr&gt; 
            &lt;? } ?&gt; 
          &lt;/table&gt; 
      &lt;/form&gt;&lt;/td&gt; 
    &lt;/tr&gt; 
  &lt;/table&gt; 
  </code></pre>
  
  <p>Here is my delete.php file:</p>
  
  <pre><code>&lt;?php 
  include("conn.php"); 
  $recsno=$_GET["recsno"]; 
  $data=trim($recsno); 
  $ex=explode(" ",$data); 
  $size=sizeof($ex); 
  for($i=0;$i&lt;$size;$i++) { 
      $id=trim($ex[$i]); 
      $sql="delete from $branch where sn='$id'"; 
      $result=mysql_query($sql,$connection) or die(mysql_error()); 
  
  } 
  header("location: index.php"); 
  ?&gt;
  </code></pre>
  
  <p>The problem is when I check 1 row, and click delete, it is deleting all of the rows, like I've clicked select all (which I didn't do). Thank you in advance.</p>