title: Deleting specific row from a table in MySQL using PHP
body: <p>I know this question has been asked too many times but I've searched and found nothing to solve my problem. In the table I have 4 columns: <code>id</code> (auto increment and primary key), <code>type</code>, <code>quantity</code> and <code>date</code>. The problem is when I press delete link it won't delete specific row I want and please forget about code injection, this is meant to be a sample program. Thanks.</p>
  
  <p>The code for a table is like this:</p>
  
  <pre><code>&lt;div id="content" align="center"&gt;
  &lt;table border="1"&gt;
  &lt;tr&gt;
  &lt;td&gt;Item&lt;/td&gt;
  &lt;td&gt;Quantity&lt;/td&gt;
  &lt;td&gt;Date&lt;/td&gt;
  &lt;td&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;?php
  include("connect.php");
  $query=("SELECT * FROM purchase");
  $result=mysql_query($query);
  while($row=mysql_fetch_array($result))
  {
  ?&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;?php echo $row['1'];?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;?php echo $row['2'];?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;?php echo $row['3'];?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;a href="delete.php"&gt;Delete&lt;/a&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;?php
  }
  ?&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And the delete function:</p>
  
  <pre><code>&lt;?php
  include("connect.php");
  
  $host="localhost";
  $user="root";
  $pass="";
  $db_name="proyek";
  $tbl_name="purchase";
  
  mysql_connect("$host", "$user", "$pass")or die("Cannot connect to SQL."); 
  mysql_select_db('$db_name');
  $query=("SELECT * FROM purchase");
  $result=mysql_query($query);
  $row=mysql_fetch_array($result);
  $id=$row[0];
  
  mysql_query("DELETE from purchase WHERE id='$id'");
  
  header("location:purchasehistoryadmin.php");
  ?&gt;
  </code></pre>