douyun3631 2013-02-01 07:13
浏览 39
已采纳

未定义的变量$ submit

I'm getting an error which states: Notice: Undefined variable: submit on line 4. I have no clue why since I have defined it with the submit button? Can someone please explain why? Don't really see the problem here.

<?php

                if($submit)
                {
                $sql = "INSERT INTO personnel (first, last, username, department, email) VALUES ('$first','$last','$username','$department','$email')";
                $add = mysql_query($sql);
                echo "<div class='confirmation-box round'>Thank you! New user have been added</div>";
                }
                else
                {
                ?>
                <form method="post" action="useradd.php">

                    <fieldset>

                    <p>
                        <label for="simple-input">Firstname</label>
                        <input type="text" id="first" name="firstname" class="round default-width-input" />
                    </p>
                    <p>
                        <label for="simple-input">Lastname</label>
                        <input type="text" id="last" name="lastname" class="round default-width-input" />
                    </p>
                    <p>
                        <label for="simple-input">Username</label>
                        <input type="text" id="username" name="username" class="round default-width-input" />
                    </p>
                    <p>
                        <label for="simple-input">Department</label>
                        <input type="text" id="department" name="department" class="round default-width-input" />
                    </p>
                    <p>
                        <label for="simple-input">Email</label>
                        <input type="text" id="email" name="email" class="round default-width-input" />
                    </p>
                        <input type="Submit" name="submit" class="button round blue image-right ic-add text-upper" value="Add">

                    </fieldset>

                </form>
                <?php
                }
                ?>

(Sorry for stupid question, kinda new at php)

  • 写回答

5条回答 默认 最新

  • duanlie7447 2013-02-01 07:14
    关注

    This is a typical old school case of register_globals usage. It decides whether or not register the EGPCS (Environment, GET, POST, Cookie, Server) variables as global variables. Nobody does that anymore.

    Change it to this:

    if (!empty($_POST['submit'])) {
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错