日期:2014-05-17  浏览次数:20407 次

关于服务器提交和响应的问题
我这里有一个例子 我是新手 初学来着
我每次第一次提交数据库表会更新 表格里面则不会 需要第二次提交表格里面才会出现数据库的最新数据
我应该怎么解决呢?
PHP code

<html>
<head>
  <title>connect db</title>
</head>
<body>


<form action="/aaa.php" method="post">
    <table border=1>
    <?php
    $link=mysql_connect("localhost","root","");
    mysql_select_db("s");
    $result=mysql_query("select Name from stud");
    for($a=0;$a<3;$a++)
    {
        echo "<tr>";
        for($b=0;$b<3;$b++)
        {
            $c="LL".$a.$b;
            if($l=mysql_fetch_array($result,MYSQL_NUM))
            {
                $$c=$l[0];
                echo "<td><input type=\"text\" name=\"lll".$a.$b."\" value=".$$c."></td>";
            }
            else
            {
                $$c="";
                echo "<td><input type=\"text\" name=\"lll".$a.$b."\" value=".$$c."></td>";
            }
        }
        echo "</tr>";
    }
    ?>
</table>
<input type="text" name="Name">
<input type="text" name="Age">
<input type="submit" name="submit1" value="tj">
<?php 
if($_POST["Name"]!="" and $_POST["Age"]!="")
{
    mysql_query("insert into stud select last_insert_id(),'".$_POST["Name"]."',".(int)$_POST["Age"]);
    for($a=0;$a<3;$a++)
    {
        for($b=0;$b<3;$b++)
        {
            $c="LL".$a.$b;
            if($l=mysql_fetch_array($result,MYSQL_NUM))
            {
                $$c=$l[0];
            }
            else
            {
                $$c="";
            }
        }
    }
}
else
{
    print "格式不正确";
}
?>
</form>

</body>
</html> 



------解决方案--------------------
你把两段php的顺序交换以下即可。