2
I’m having a problem in a php form that I don’t know how to fix. I have a file called login.php that contains a form that sends the data via POST to the.php data file. In the.php data I do the necessary processing. It turns out that whenever I try to simulate a login, I get the following message: Notice: Undefined variable: usuario Notice: Undefined variable: pass My login.php code is this:
<!DOCTYPE html>
<form method="POST" action="dados.php">
<label>Login</label>
<input type="text" name="usuario" class="form-control" id="usuario" autocomplete="off" autofocus required>
<label for="senha">Senha</label>
<input type="password" class="form-control" id="pass" name="pass" autocomplete="off" required>
<input type="submit" value="Login" id="entrar" name="entrar">
</form>
<!-- Scripts -->
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/ocultarSenha.js"></script>
My.php data code is this:
<?php
// Conexão com o banco
$bdServidor = '127.0.0.1';
$bdUsuario = 't3carvvo_MatheusEdnei';
$bdSenha = 't3carvvo_#';
//$bdUsuario = 'root';
//$bdSenha = 'root';
$bdBanco = 't3carvvo_pessoas';
$conexao = mysqli_connect($bdServidor, $bdUsuario, $bdSenha, $bdBanco);
if(mysqli_connect_errno($conexao)) {
echo "Problemas para conectar no banco. Erro:";
echo mysqli_connect_errno;
die();
}
if (isset($_POST['usuario'])) {
$usuario = $_POST['usuario'];
echo "entrei no usuario ";
echo $usuario;
} else {
echo "não entrei no usuario";
}
if (isset($_POST['pass'])) {
$pass = MD5($_POST['pass']);
echo "entrei na senha ";
echo $pass;
} else {
echo "não entrei na senha";
}
$contem = strpos($usuario, '@');
if($contem === false){
echo "cpf";
} else {
$sqlSelecionarEmail = "SELECT email FROM pessoa WHERE email = '$usuario'";
$selecaoEmail = mysqli_query($sqlSelecionarEmail,$conexao);
$arrayEmail = mysqli_fetch_array($selecaoEmail);
print($arrayEmail);
$loginarray = $arrayEmail['email'];
$sqlSelecionarSenha = "SELECT senha FROM pessoa WHERE senha = '$pass'";
$selecaoSenha = mysqli_query($sqlSelecionarSenha,$conexao);
$arraySenha = mysqli_fetch_array($selecaoSenha);
$senhaArray = $arraySenha['senha'];
if($loginarray === $usuario and $senhaArray === $pass ) {
echo"
<script language='javascript' type='text/javascript'>
alert('Login e senha corretos');
//window.location.href='dados.php';
</script>
";
} else {
echo"
<script language='javascript' type='text/javascript'>
alert('Login ou senha incorretos');
window.location.href='dados.php';
</script>
";
}
}
?>
Edit 1:
I modified the code a little bit and now the return is as follows:
Notice: Undefined index: usuario in C: xampp htdocs t3carvvo_tarefa1 dados.php on line 31
Notice: Undefined index: pass in C: xampp htdocs t3carvvo_tarefa1 dados.php on line 32
Notice: Undefined index: usuario in C: xampp htdocs t3carvvo_tarefa1 dados.php on line 33
it does not display the line where is giving the error?
– Tales Peres
It prints the "I didn’t sign in to the user" message indicating that isset($_POST['user']) returns an empty value. If I withdraw this check it informs me that there is an error when I do : $user = $_POST['user'];
– MatheusEdnei
tried to give a
var_dump($_POST)
, to see if you’re afraid of something?– Tales Peres
I did it now and it returned to me: array(0) { } . Looking at the Chrome developer tools in the network tab I noticed that the "Request method" is indicating that the request was of type GET, even putting the form as POST.
– MatheusEdnei