marciofilipee Posted April 28, 2015 at 11:52 PM Report Share #582092 Posted April 28, 2015 at 11:52 PM (edited) Olá estou com um sistema de login a base de dados estou com este erro Fatal error: Call to a member function num_rows() on a non-object in /home/marciofi/public_html/login_func.php on line 7 login_func.php o código é o seguinte da linha 7 if($query->num_rows() == 1){ // login com sucesso.. Código completo < ?php include 'init.php'; //CONSULTA DO UTILIZADOR $query = "Select * from clientes where nome='" . $_POST['nome'] . "' and password='" . $_POST['password'] . "'"; $resultado=mysql_query($query); if($query->num_rows() == 1){ // login com sucesso.. //COLOCA NA VARIAVEL LINHA OS DADOS DA CONSULTA $linha=mysql_fetch_array($resultado); //COLOCA O UTILIZADOR EM SESSAO $_SESSION['nome']=$linha['nome']; if($tipo == 0){ // Utilizador faz algo... header("location: user.php"); }else{ // Administrador faz algo... header("location: admin.php"); } } // erro ao efectuar login.. else //CASO NAO COINCIDAM { //REDIRECCIONA PARA A PAGINA INICIAL REPORTANDO O ERRO header("location: login.php?erro=1"); } ?> Edited April 29, 2015 at 08:19 AM by apocsantos tag code + geshi Link to comment Share on other sites More sharing options...
Cerzedelo Posted April 29, 2015 at 07:42 AM Report Share #582096 Posted April 29, 2015 at 07:42 AM De uma análise no seguinte: http://php.net/manual/en/function.mysql-num-rows.php Atenção que as funções mysql estão decrepted, pelo deve passar a usar, mysqli ou PDO. Link to comment Share on other sites More sharing options...
bioshock Posted April 29, 2015 at 11:21 AM Report Share #582108 Posted April 29, 2015 at 11:21 AM (edited) Estás a misturar conceitos diferentes como já referido. No entanto, a variável de identificação está errada. if($query->num_rows() == 1) // <-- $query é texto simples.. if(mysql_num_rows($resultado) == 1) // <-- $resultado é a query devolvida pelo MySQL Edited April 29, 2015 at 11:22 AM by bioshock Link to comment Share on other sites More sharing options...
capesone Posted April 29, 2015 at 11:42 AM Report Share #582109 Posted April 29, 2015 at 11:42 AM (edited) melhores usar o mysqli e cuidado com o injection $query = $ligaçao_mysqli -> query("") $query -> execute(); if(myslqi_num_rows($query)) # passa else #nao passa agora nao tenho tempo para mais Edited April 29, 2015 at 01:15 PM by apocsantos geshi Link to comment Share on other sites More sharing options...
marciofilipee Posted April 29, 2015 at 08:36 PM Author Report Share #582140 Posted April 29, 2015 at 08:36 PM (edited) Obrigado agora não esotu a conseguir fazer login código do fórum <form class="form-inline" form name="login" "method="post" action="login_func.php"> <input type="login" name="nome" class="form-control" placeholder="Nome"> <input type="password" name="password" class="form-control" placeholder="Password"> <button type="submit" value="Login" class="btn btn-default">Entrar</button> <?php if(isset($_GET['erro'])) //SE EXISTIR ERRO echo "<font color=\"#FF0000\">Erro no login. Tente novamente.</font>" ?> </form> código do login_func.php <?php include 'init.php'; //CONSULTA DO UTILIZADOR $consulta = "Select * from clientes where nome='" . $_POST['nome'] . "' and password='" . $_POST['password'] . "'"; $resultado=mysql_query($consulta); if (mysql_num_rows($resultado)>0) //SE O EMAIL E A PASSWORD COINCIDIREM { //COLOCA NA VARIAVEL LINHA OS DADOS DA CONSULTA $linha=mysql_fetch_array($resultado); //COLOCA O EMAIL EM SESSAO $_SESSION['nome']=$linha['nome']; //REDIRECCIONA A PAGINA PARA A PAGINA SECRETA header("location: admin.php"); } else //CASO NAO COINCIDAM { //REDIRECCIONA PARA A PAGINA INICIAL REPORTANDO O ERRO header("location: login.php?erro=1"); } ?> Edited April 29, 2015 at 10:44 PM by apocsantos geshi Link to comment Share on other sites More sharing options...
capesone Posted April 30, 2015 at 12:06 AM Report Share #582174 Posted April 30, 2015 at 12:06 AM (edited) if (mysql_num_rows($resultado)>0) nao precisas ai do > 0, se a variavel for 0, o if retorna false, logo sem isso vai funcionar tambem! Agora 2 perguntas: Fizeste o session_start? Na página admin.php tas a validar se a session existe certo? Se as respostas a essas perguntas sao ambas sim, Verifica se a $linha[nome] tem algum conteudo la dentro antes de criares o indice da sessão Edited April 30, 2015 at 12:07 AM by capesone Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now