Form html does not send the data to the php files

0

The login form does not send the data to the php file that is in the previous folder. I already put var_dump($_POST); but it does not show any error or result. The form file name is login.php, when I put it in the same folder as the form processing php file, it redirects to the folder where it was, the url is: localhost / root folder name / folder name where it was /login.php. What can it be?

front / login.php:     

    include_once '../back/login.php';
    if (!isset($_SESSION['log'])) 
    {

    ?>

    <html lang="pt-BR">
    <head>
        <title>TodoIF</title>
        <meta charset="utf-8">
    <!--    <link rel="stylesheet" type="text/css" href="front.css">-->
    </head>
    <body>
        <div class="tabs">
            <label for="tab1" id="tab_label" class="tab_label">LOGIN</label>
            <div class="tab_content"></div>
                <h2>BEM VINDO!</h2>
                <form method="post" action="../back/login.php">
                    <label for="email">E-mail:</label>
                    <input type="text" id="email" name="email"/><br><br>
                    <label for="key">Senha:</label>
                    <input type="text" type="password" name="senha"/><br><br>

                    <button type="submit" name="logar">Login</button>

                    <div class="links">
                        <a href="" style="font-size: 14px;">Não tenho cadastro</a><br>
                        <a href="">Esqueci minha senha</a>
                    </div>
                </form> 
        </div>
    </body>
    </html>

    <?php
    }else
    {
        $_SESSION['msg'] = "Você já está logado";
        header("location: dashbord.php");
    } 
    ?>

back / login.php:

<?php

include_once 'connect.php'; 
include_once 'bcrypt.php';
include_once 'register.php';
//include_once 'loginfront.php';

if(isset($_POST['logar']))
{   
    var_dump($_POST);
    $dbh= Conexao();
    $email= $_POST['email'];
    $password_user= $_POST['senha'];

    try {

        $sql= ("SELECT 'id', 'email', 'password_user' FROM 'users' WHERE email = '$email'");
        $result= $dbh->prepare($sql);
        $result->execute(array('email'=> $email,'senha'=> $password_user));
        $result= $result->fetch();
        var_dump($result);
        if (Bcrypt::check($password_user, $hash) == $hash) {
                session_start();
                $_SESSION["id"] = $result["id"]; 
                header("Location: ../front/dashbord.php");
        }else {
            echo "<script>alert('Login ou senha inválidos. Tente novamente')</script>"; 
        }
    }catch(PDOexception $error) {
        echo 'Erro ao fazer login.'.$error->getMessage();
    }

}
?>
    
asked by anonymous 25.11.2017 / 01:13

1 answer

0

Good morning, why do not you try everything in one file?

<?php

include_once 'connect.php'; 
include_once 'bcrypt.php';
include_once 'register.php';

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

var_dump($_POST);
$dbh = new Conexao();
$email = $_POST['email'];
$password_user = $_POST['senha'];

try {

    $sql= ("SELECT 'id', 'email', 'password_user' FROM 'users' WHERE email = '$email'");
    $result= $dbh->prepare($sql);
    $result->execute(array('email'=> $email,'senha'=> $password_user));
    $result= $result->fetch();
    var_dump($result);
    if (Bcrypt::check($password_user, $hash) == $hash) {
            session_start();
            $_SESSION["id"] = $result["id"]; 
            header("Location: ../front/dashbord.php");
    }else {
        echo "<script>alert('Login ou senha inválidos. Tente novamente')</script>"; 
    }
}catch(PDOexception $error) {
    echo 'Erro ao fazer login.'.$error->getMessage();
}

}

if (!isset($_SESSION['log'])) {
?>

<html lang="pt-BR">
<head>
    <title>TodoIF</title>
    <meta charset="utf-8">
<!--    <link rel="stylesheet" type="text/css" href="front.css">-->
</head>
<body>
    <div class="tabs">
        <label for="tab1" id="tab_label" class="tab_label">LOGIN</label>
        <div class="tab_content"></div>
            <h2>BEM VINDO!</h2>
            <form method="post" action=" <?php $_SERVER['PHP_SELF']; ?>">
                <label for="email">E-mail:</label>
                <input type="text" id="email" name="email"/><br><br>
                <label for="key">Senha:</label>
                <input type="text" type="password" name="senha"/><br><br>

                <button type="submit" name="logar">Login</button>

                <div class="links">
                    <a href="" style="font-size: 14px;">Não tenho cadastro</a><br>
                    <a href="">Esqueci minha senha</a>
                </div>
            </form> 
    </div>
</body>
</html>
<?php

} else {

    $_SESSION['msg'] = "Você já está logado";
    header("location: dashbord.php");

} 

?>
    
25.11.2017 / 11:45