douyue8685 2016-12-05 04:40
浏览 60
已采纳

尝试从html按钮POST时未定义索引错误

I'm trying to echo a password hash from a login form I created. I'm not sure why I'm getting the error **Undefined index: signinbtn in D:\XAMPP\htdocs\login_page.php **. I'm using the POST method for my form. Nothing happens when I click the signinbtn.

<form action="login_page.php" method="POST">
    <div id="container" name="container">
        <input type="email" id="email" name="email" placeholder="Email">
        <input type="password" id="pswd" name="pswd" placeholder="Password">
        <input type="submit" name="signinbtn" value="Login"/>

        <div id="logo" name="logo">
            <img src="captifiy.png" alt="logo" id="logo" width="194" height="218px"/>
        </div>

        <div class="forgotpw"><a href="#">Need Help Logging In?</a>
        </div>
    </div>
</form>
<?php
if($_POST['signinbtn']) {
    $email = $_POST['email'];
    $pswd  = $_POST['pswd'];

    if($email) {
        if($pswd) {
            require("dbh.php");
            $pswd = md5(md5("wrfoiv" . $pswd . "iujq3b"));
            echo "$pswd";
            $query = mysql_query("");
            mysql_close();
        } else {
            echo "You must enter your password.";
        }
    } else {
        echo "You must enter your email.";
    }
}
  • 写回答

1条回答 默认 最新

  • donglie7268 2016-12-05 04:46
    关注

    Change your line from

    if ($_POST['signinbtn']) {
    

    to

    if (isset($_POST['signinbtn'])) {
    

    This checks for existence of variable in order to prevent code crash when loading the page for the first time. As at that time $_POST array does not exist and hence you get this error

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题