step by step, this is what you are doing aka why this is happening:
1) check if post variable delete is set:
if (isset ($_POST['delete'])){
2) fetch all posts from database:
$result = mysql_query ("SELECT * FROM posts") or die(mysql_error());
3) fetch the first item out of the $result array
$data = mysql_fetch_array($result);
4) delete the item we just fetched
mysql_query ("DELETE FROM posts WHERE id = $data[id]");
5) redirect to main.php
header("Location: main.php");