php博客不会显示前2个数据库行

I'm working on my own simple blog. I got it working so far only 1 very irritating bug remaining. If I have 4 rows of data in my databse the first 2 (with the lowest ID) won't show up. So if I add a new 3rd row only the first row will pop-up my screen and it will take 2 new posts before the 3rd row will show up. If I turn around the sequence of ID's it does work if I have 2 useless posts in my database. But ofcourse I want the higher id's to show on top.

Here is the code for putting the database info on the screen:

<?php
require('config.inc.php');
require('template.inc.php');
require('functions.inc.php');
include_once('insert.php');

$query="SELECT * FROM blog ORDER BY ID DESC";
$result=mysql_query($query);

$db_field = mysql_fetch_assoc( $result );
mysql_fetch_assoc( $result );

mysql_close();

htmlOpenen('ServerSideBlog');
while ($db_field = mysql_fetch_assoc($result) ) {
echo'
<span class="post">
    <h1>'.$db_field['title'].'</h1>
    <h2>'.$db_field['date'].'</h2>
    <p>'.$db_field['contents'].'</p>
    <h3>Hoogachtend, Sincerely, Aufrichtig, sinceramente,</h3>
    <h4>'.$db_field['author'].'</h4>
';
}
htmlSluiten();
?>

And here the code for adding the posts in the database:

<?php
$db_host = "db.jxxxxx.com";
$db_username = "md2xxxx230";
$db_pass = "J9xxxx58";
$db_name = "md2xxxxx230";

@mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to      mysql");
@mysql_select_db("$db_name") or die ("no database");

if ($_POST['parse_var'] == "new"){

    $title=$_POST['title'];
    $contents=$_POST['contents'];
    $author=$_POST['author'];
    $date=$_POST['date'];
    $date = strftime("%b %d, %y", strtotime($date));

    $sqlcreate = mysql_query("INSERT INTO blog (date, title, contents, author)
            VALUES(now(),'$title','$contents','$author')");
}

?>

I can't find any solution for the problem... Hope I can get some awnsers here :)

why did you put this before while loop ?

$db_field = mysql_fetch_assoc( $result );
mysql_fetch_assoc( $result );

mysql_close(); 

and secondly you have close the mysql connection before -

while ($db_field = mysql_fetch_assoc($result)

You call mysql_fetch_assoc in three places. Two times before you enter your while loop. Those two times returns the first two rows. So when you enter your while loop you start from row #3. Since the code to display the posts are inside the whileloop it will, obviously, not show the first two posts.

Remove the rows

$db_field = mysql_fetch_assoc( $result );

and

mysql_fetch_assoc( $result );

and move

mysql_close();

to after your while loop and it will most likely do what you want.

Sidenote:

The way data is added to the database is extreamly unsecure. The row

 $sqlcreate = mysql_query("INSERT INTO blog (date, title, contents, author)
            VALUES(now(),'$title','$contents','$author')");

along with no filtering of the inserted data show that it's highly vulnerable for injection attacks. Both arbitrary SQL code and Javascript could be executed.

Some information for you:

http://en.wikipedia.org/wiki/SQL_injection

http://en.wikipedia.org/wiki/Cross-site_scripting