0
The login form does not send the data to the php file that is in the previous folder. I have already put var_dump($_POST);
but shows no error or result.
The form file name is login.php, when I put it in the same folder as the php form processing file, it redirects to the folder where it was, the url is: localhost/root folder name/name of the folder where he was staying/login.php. What can 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();
}
}
?>
I tried what you said, but what makes it like
$_POST
take the html data is thenew
before theConexão()
. But it gives an error because we can only create instances of classes, andConexão()
is a function. Also the data does not pass$dbh = new Conexao();
even putting it all in one file. But thanks for trying– user87737