表单中PHP的错误提示:Notice: Undefined index: submit in D:\wamp\www\bbs\add.php on line 4

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010696927/article/details/25502917

       最近学习php,写留言版的时候,代码如下红字部分,在浏览器中测试却显示错误信息:Notice: Undefined index: submit in D:\wamp\www\bbs\add.php on line 4

<?

include("conn.php");

if($_POST['submit']){
 
$sql="insert into message (id,user,title,content,lastdate) values ".
"('','$_POST[user]','$_POST[title]','$_POST[content]',now())";                                              
 
 }

?>
<form action="add.php" method="post">
用户:<input type="text" size="10" name="user" /><br>
标题:<input type="text" name="title" /><br/>
内容:<textarea name="content"></textarea><br/>
<input type="submit" name="submit" value="发布留言"/>
</form>


解决办法是:原因是数组键submit不存在,将代码if($_POST['submit'])  改为if (isset($_POST['submit']))即可
最好的办法:修改配置文件 
打开php.ini文件
error_reporting设置: 

找到error_reporting=E_ALL 

修改为error_reporting=E_ALL & ~E_NOTICE 


猜你喜欢

转载自blog.csdn.net/u010696927/article/details/25502917
今日推荐