Home  >  Article  >  Backend Development  >  $_POST[]有关问题

$_POST[]有关问题

WBOY
WBOYOriginal
2016-06-13 13:21:01927browse

$_POST[]问题
看PHP100的视频教程中的留言板部分,里面有句是这么写的:

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
if($_POST['submit'])
    {
        $sql = "insert into msg (id, userid, contant, oppeardata) values ('', '999', '$_POST[contant]', Now())";
        print $sql;
        $sql_return = mysql_query($sql);
        if(!$sql_return)
        {
            print("发表留言错误").mysql_error();
            exit();
        }
        print("发表留言成功"); 



问题是:$_POST['submit']会出错:Notice: Undefined index: submit in /var/ftp/htdocs/index.php on line 47
submit 是表单按钮的name
$_POST[submit]的错误提示 Notice: Use of undefined constant submit - assumed 'submit' in /var/ftp/htdocs/index.php on line 47

初学,不太明白为啥,和教程里的也对比了,一样的吖。

------解决方案--------------------
PHP code
if (isset($_POST['submit']))
<br><font color="#e78608">------解决方案--------------------</font><br>第一个notice是因为你调用了不存在的变量($_POST['submit'])<br><br>第二个$_POST[submit]是因为你submit两边没有引号引起来,应该$_POST['submit']或者$_POST["submit"] <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article: php进制变换 Next article: strstr中汉字怎么编码