username = $_POST["username"];
......$_POST[""]

解决方案 »

  1.   

    你要知道PHP的处理流程,
    只有表单被提交后$_POST数组才会被填充相应的值,否则会导致Undefined index的错误
    流程应该这样<?php
    if( count( $_POST ) > 0 )
    {
     //插入数据
      insertMsg($_POST['name'], $_POST['title'], $_POST['message']);
    }
    else
    //显示数据和表单
    {
    ?>
    <html>
    <head>
    <title>简易留言板</title>
    </head>
    <body>
    <center><h1>简易留言板</h1></center>

    <form action="index.php" method="POST">
    姓名:<input name="username" type="text"><br/>
    标题:<input name="title"  type="text"><br/>
    <textarea  name="message" cols="50" rows="20">请在这里留言</textarea><br/>
    <input type="submit" value="提交">
    </form>
    <?php printMsg();?>
    </body>
    </html>
    <?php }?>
      

  2.   

    if( count( $_POST ) > 0 ) 
    {
    这个办法不错;
      

  3.   

    如果$_POST本来就有默认值,那count肯定大于0. 最近看了本书,觉得用isset($_post['submit'])比较好,不过还是谢谢楼上的各位