Jump to content

Ajuda com erro PHP SQL


marciofilipee
 Share

Recommended Posts

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 by apocsantos
tag code + geshi
Link to comment
Share on other sites

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 by apocsantos
geshi
Link to comment
Share on other sites

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 by capesone
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.