1
I have a system that has a pv_user table and a pv_position.
I would like to make a check according to the position the user will be redirected to different page.
I have the code below:
$result = "select * from pv_usuario where login = '$login' and senha = '$senha' and ativo = 1";
$sql_execute = mysql_query($result);
$sql_verifica = mysql_num_rows($sql_execute);
if($sql_verifica > 0)
{
if($senha == 'giga123' )
{
session_start();
$_SESSION['login'] = $login;
$_SESSION['senha'] = $senha;
header('location:../../mpv/Login/reset.php');
}
else {
session_start();
$_SESSION['login'] = $login;
$_SESSION['senha'] = $senha;
header('location:../../mpv/index.php');
exit;
}
}else
{
session_destroy();
unset($_SESSION['login']);
unset($_SESSION['senha']);
session_destroy();
header('location:../../mpv/acesso_negado.php');
exit;
}
I thought I’d do something like that and put inside the first if above:
$query = $con->query("select * from pv_usuario where login = '$login' and ativo = 1");
while($reg = $query->fetch_array())
{
if( $reg["cod_usuario"] == 1 )
{
header('location:../../mpv/Atendimento/index.php');
}
else if($reg["cod_usuario"] == 2)
{
header('location:../../mpv/Tecnico/index.php');
}
}
Only it’s not working. What should I do?
I’m pretty sure the problem is here:
$reg["cod_usuario"]
try to change into this:$reg["COD_USUARIO"]
– MarceloBoni
Some remarks: 1- What kind of error are you giving? 2- The "cod_usuario" field belongs to the "pv_usuario" table itself, right? 3- In the codes does not mention "pv_cargo" anywhere, I believe you are testing with specific users, right? 4- If the second code block is within the first IF (if($sql_checks > 0)), there is no need for the second query, this can save you some code :)
– Eder Silva
A, and I also believe it will be necessary to use a line identifier in your case
$reg[0]["COD_USUARIO"]
– MarceloBoni
you didn’t forget to give a
exit
after theheader('Location: ...')
?– Édipo Costa Rebouças