2
Like I did the right php as my teacher passed, I changed all the names and it’s all right, I already checked, but when I log in, he doesn’t log in, he just updates the page and doesn’t redirect to the person’s profile page as it is to be done.
The code is this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
include ('config.php');
session_start();
if ($_POST['botao']=="Entrar"){
$query = "SELECT * FROM usuarios WHERE email = '".$_POST['email']."' AND senha = '".$_POST['senha']."' ";
$result = mysql_query($query) or print mysql_error();
if(mysql_num_rows($result)>0){
while ($coluna=mysql_fetch_array($result)) {
$_SESSION["id_usuario"]= $coluna["id"];
$_SESSION["email"] = $coluna["email"];
$_SESSION["senha"] = $coluna["senha"];
$_SESSION["UsuarioNivel"] = $coluna["nivel"];
if($coluna['nivel'] == "USER"){
header("Location: perfil.php");
exit;
}
elseif($coluna['nivel'] == "ADM"){
header("Location: restrita.php");
exit;
}
else {
echo "Nenhum nível selecionado!";
}
// ----------------------------------------------
}
} else {
echo "Login ou Senha Incorreto";
}
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data" name="cadastro" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>
</head>
<style type="text/css">
</style>
<body>
<table border="0" class="banner"><tr><td colspan="4" align="center"><img src="banner.jpg" height="250" width="900"/></td></tr></table>
<br>
<table border="0" align="center" width="910">
<tr class="link">
<td> <a href="principal.php"> Home </a> </td>
<td> <a href="perfil.php"> Meu perfil </a> </td>
<td> <a href="login.php"> Entrar </a> </td>
<td> <a href="login_funcionario.php"> Área restrita </a> </td>
</tr>
</table>
<br /> <br />
<table border="0" align="center">
<tr> <td colspan=3 align=center class="titulo"> Login </td> </tr>
<tr> <td class="texto"> Email: </td> <td colspan="2"> <input type="text" name="email" maxlength="30" class="input"> </td> </tr>
<tr> <td class="texto"> Senha: </td> <td colspan="2"> <input type="password" name="senha" maxlength="20" class="input"></td></tr>
<tr> <td colspan=2 align=right>
<input type="submit" name=botao id="botao" value="Entrar" class="botao">
<input type="submit" name=botao value="Esqueci a senha" class="botao2">
</td> </tr>
<tr> <td colspan=2 align=center>
<br />
<font class="texto"> Não é cadastrado? </font>
<br />
<font class="link"> <a href="cadastro.php"> Cadastre-se aqui </a> </font>
</td>
</tr>
Your teacher recommended using
@
?, is sending by post?– rray
if you take the @ it gives news, but does not change in much, still not working and yes, by post
– AliniS
Edit the question and add the
form
shipping, you need to treat this notice, usually an if withisset()
and the value check already resolves. Related:Why do they say using @arroba to suppress errors is a bad practice?– rray
Play the line
<form ...
down the tag<body>
remember to close the tagform
in the end.– rray
session_start(); should be the first thing in your php file. keep that in mind! Nor is it good policy to get the form before the head, alias, had never seen it like this.
– pc_oc
Another note, you are buying an encrypted password with text, this will always give authentication error. which encryption method was used for the password?
– pc_oc