1
I am making a PHP site for my TCC, and one of the guidelines given was to remove the level selection, and that this was done automatically by the system. My teacher said it was just to remove the select code, but if I do it nothing happens. Follow below the HTML and PHP codes
<form id="form2" name="form2" method="post" action="php/usuarioautenticado.php">
<input type="text" name="username" id="username" required="required" placeholder="Usuário"/>
<input type="password" name="senha" id="senha" required="required" placeholder="Senha"/>
<select name="nivel" form="form2" class="select">
<option value="">Escolha seu nível</option>
<option value="admin">Administrador</option>
<option value="usuario">Usuário</option>
</select>
<input type="submit" name="enviar" id="enviar" value="Enviar" />
<?php // Código para verificação no banco do login e senha
if (isset ($_POST ['enviar'])){// se o campo enter for clicado
$username=$_POST['username'];
$senha=$_POST['senha'];
$nivel=$_POST['nivel'];
$query = @mysql_query ("SELECT * FROM cadastro WHERE username='$username' AND senha ='$senha' AND nivel='$nivel'"); // Verifique no banco se o login e a senha digitados existem.
$conta = @mysql_num_rows ($query);// conte os dados do banco selecionados na variável query
if ($conta == '0') {// se o valor digitado não existir
echo "<script language= 'javascript'> window.alert('Os campos não correspondem');</script>";
header ("LOCATION: ../index.php");
}else{
while ($resultado= @mysql_fetch_array($query) ){// estamos verificando os dados do banco em uma lista ( array )
$id = $resultado ['id'];
$username= $resultado ['username'];
$senha = $resultado ['senha'];
$nivel = $resultado ['nivel'];
// vamos abrir a sessão pois para que possamos manipular páginas com nivel é preciso abrir a sessão para manter os dados abertos e também deve ter um botão de sair para destruir a sessão.
session_start ();
$_SESSION['id'] = $id;
$_SESSION['username'] = $username;
$_SESSION['senha'] = $senha;
$_SESSION['nivel'] = $nivel;
// redirecionar para página correta
if ($nivel == 'admin'){
header ("LOCATION: select.php");
}elseif ($nivel =='usuario'){
header ("LOCATION: mostradados.php");
}else{
return false;
}
}}
}
?>
Have you tried removing the
AND nivel='$nivel'
in query?– Valdeir Psr
Yeah, I tried a couple of times and it wasn’t.
– user125387
Click on [Edit] and posted as you are currently doing.
– Valdeir Psr
What do you mean? I’m sorry, I’m new here, I don’t really know how the site works :/
– user125387