0

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.";
    }
}
TimBrownlaw
  • 5,457
  • 3
  • 24
  • 28
sortinousn
  • 637
  • 2
  • 9
  • 27
  • Is this happening when you are loading the page for first time? – bugwheels94 Dec 05 '16 at 04:44
  • If you're writing new code, **_please_ don't use the `mysql_*` functions**. They are old and broken, were deprecated in PHP 5.5 (which is so old it no longer even receives security updates), and completely removed in PHP 7. Use [`PDO`](https://secure.php.net/manual/en/book.pdo.php) or [`mysqli_*`](https://secure.php.net/manual/en/book.mysqli.php) with _prepared statements_ and _parameter binding_ instead. See http://stackoverflow.com/q/12859942/354577 for details. – ChrisGPT was on strike Dec 05 '16 at 04:45
  • Please don't roll your own password hashing solution. Use [`password_hash()`](https://secure.php.net/manual/en/function.password-hash.php) and [`password_verify()`](https://secure.php.net/manual/en/function.password-verify.php) instead. – ChrisGPT was on strike Dec 05 '16 at 04:47
  • Thanks for the tip! I'll look in to it. – sortinousn Dec 05 '16 at 04:52

1 Answers1

0

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

bugwheels94
  • 30,681
  • 3
  • 39
  • 60