<?php
include ("conn.php");
if($_POST['submit']){
$user=$_POST["user"];
$title=$_POST["title"];
$content=$_POST["content"];
$sql="insert into bbs (id,user,title,content,lastdate) value ('',$user,$title,$content,now())";
echo $sql;
}
?><form action="index.php" method="post">
用户:<input type="text" size="10" name="user"/><br/>
标题:<input type="text" size="20" name="title"/><br/>
内容:<textarea name="content" ></textarea><br/>
<input type="submit" name="submit" value="提交"/>
</form>
预览的时候它提示:
Notice: Undefined index: submit in E:\wamp\www\Test\index.php on line 4望高手给予解答!!!

解决方案 »

  1.   

    这个提示的意思是说你没有定义$_POST['submit']这个变量,如果表单提交了就不会有提示,因为post过来以后submit就有了‘提交’这个值,但是在提交之前没有定义,所以会有提示,
    isset($_POST['submit'])
    判断前加这个判断
    也可以if(@$_POST['submit']){
    //内容
    }
    @是屏蔽警告
      

  2.   

    代码修改如下:
    <?php
    include ("conn.php"); if(isset($_POST['submit'])){
    $user=$_POST["user"];
    $title=$_POST["title"];
    $content=$_POST["content"];
    $sql="insert into bbs (id,user,title,content,lastdate) value ('',$user,$title,$content,now())";
    echo $sql;
    }
    ?><form action="index.php" method="post">
    用户:<input type="text" size="10" name="user"/><br/>
    标题:<input type="text" size="20" name="title"/><br/>
    内容:<textarea name="content" ></textarea><br/>
    <input type="submit" name="submit" value="提交"/>
    </form>