-1
I am set up a system to facilitate communication and support to representatives of the company where I work. The rest of the page already exists, but I need to make each type of user be directed to a different page.
One of the biggest problems I’m facing is that there’s always the message that the mysql_connect
no longer works and which should be replaced by the mode PDO
.
Someone there can help me?
Follows the code
<?php
// Verifica se houve POST e se o usuário ou a senha é(são) vazio(s)
if (!empty($_POST) AND (empty($_POST['usuario']) OR empty($_POST['senha']))) {
header("Location: index.php"); exit;
}
// Tenta se conectar ao servidor MySQL
mysqli_connect('localhost', 'root', '') or trigger_error(mysql_error());
// Tenta se conectar a um banco de dados MySQL
mysqli_select_db('novosistema') or trigger_error(mysql_error());
$usuario = mysqli_real_escape_string($_POST['usuario']);
$senha = mysqli_real_escape_string($_POST['senha']);
// Validação do usuário/senha digitados
$sql = "SELECT `id`, `nome`, `nivel` FROM `usuarios` WHERE (`usuario` = '". $usuario ."') AND (`senha` = '". sha1($senha) ."') AND (`ativo` = 1) LIMIT 1";
$query = mysql_query($sql);
if (mysql_num_rows($query) != 1) {
// Mensagem de erro quando os dados são inválidos e/ou o usuário não foi encontrado
echo "Login inválido!"; exit;
} else {
// Salva os dados encontados na variável $resultado
$resultado = mysql_fetch_assoc($query);
// Se a sessão não existir, inicia uma
if (!isset($_SESSION)) session_start();
// Salva os dados encontrados na sessão
$_SESSION['UsuarioID'] = $resultado['id'];
$_SESSION['UsuarioNome'] = $resultado['nome'];
$_SESSION['UsuarioNivel'] = $resultado['nivel'];
// Redireciona o visitante
header("Location: restrito.php"); exit;
}
?>
http://answall.com/questions/579/por-que-n%C3%A3o-should-use-fun%C3%A7%C3%B5es-do-tipo-mysql
– MarceloBoni
If you are using any version of
PHP 5.5+
should keep in mind that the librarymysql_*
was discontinued, one should look for alternatives as cited in the link passed above, as themysqli_*
,PDO
, or libraries of other frameworks– MarceloBoni