$_POST from submit is not set after submitting

Viewed 31

I don't why why if (isset($_POST['login'])) is not working here. I always get the somehow here alert when I try to login. Can someone point out what I'm doing wrong?

So far I tested other name, value and rewriting it. I also copied the form and the PHP from the registration which is working.

    <?php
    require_once "./class/UserDAO.php";
    require_once "./class/DBUserDAO.php";
    $DBUserDAO = new DBUserDAO();

    session_start();

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

            echo '<script language="javascript">';
            echo 'alert("here")';  
            echo '</script>';  

        $DBUserDAO->login($_POST['email'], $_POST['password']);
    }
    else{
        echo '<script language="javascript">';
        echo 'alert("somehow here")';  
        echo '</script>'; 
    }
    ?>

    <html lang="de">
    <!DOCTYPE html>

    <?php include "php/header.php" ?>

        <body class="user-input">
        

        <?php include "php/nav.php" ?>
            <header class="header">
                <h1>Anmeldung</h1>
                <!--
                <nav class="burger">
                    <i class=" glyphicon glyphicon-list "></i>
                </nav>
                -->
            </header>
            <main>
                <div class="box-input">
                    <form action="?login=1" method="post">
                        <span class="text-center">Anmeldung</span>
                        <?php 
                            if (isset($_SESSION['success']) and $_SESSION['success'] == "Successfully created an account") {
                                echo '<label class="inputNote" for="email">Du kannst dich jetzt Anmelden</label>';
                                unset ($_SESSION['success']);
                            }
                            if (isset($_SESSION['loginError']) and $_SESSION['loginError'] == "Invalid username or password") {
                                echo '<label class="inputNote" for="email">Kein Konto mit dieser Kombination gefunden</label>';
                                unset ($_SESSION['loginError']);
                            }
                        ?>
                        <div class="input-container">
                            <input type="email" required=""
                            <?php if (isset($_SESSION['email'])){echo 'value="'.$_SESSION['email'] .'"';}?>
                            name="email" id="email"/>
                            <label for="email">Email</label>
                        </div>
                        <div class="input-container">
                            <input type="password" required="" name="password" id="password"/>
                            <label for="password">Passwort</label>
                        </div>
                    <button type="submit" class="btn" value="login" name="login">Registrieren</button>
                    </form>
                </div>
            </main>

        </body>

    </html>
1 Answers

You can't send parameters as GET request and retrieve them as POST. this line :

<form action="?login=1" method="post">

You sent "login" as GET request. You should use hidden parameter:

<form action="" method="post">
<input name="login" type="hidden" value="1">
Related