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 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂