Jump to content
Fórum Script Brasil
  • 0

Login


Cyber Plets

Question

Ola pessoal!

Eu fiz o código abaixo para checar senha e login dos usuarios.

<?php

$varlogin=$_POST['login'];

$varsenha=$_POST['senha'];

$conex=mysql_connect("localhost","","")or die("Erro ao conectar-se ao servidor My SQL.");

//linha para executar ao servidor My SQL

$bd=mysql_select_db("proc",$conex)or die("Erro ao conectar-se à base de dados.");

$resultado=mysql_query("select * from user where login=$varlogin' and senha='$varsenha'");

$linhas=mysql_num_rows($resultado);

$varnome=mysql_result($resultado,0,'nome');

if ($linhas > 0){

session_start();

$_SESSION['logado]="$varnome";

header("location:admin.php?login=$varnome");

}

else

{

header("location:index.php");

}

?>

Quando coloco a senha correta da tudo certo

Mas quando coloco uma senha errada para retornar a pagina index me da o seguinte erro

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 2 in E:\Plets\Clientes\Frango\login_chk.php on line 9

Warning: Cannot modify header information - headers already sent by (output started at E:\Plets\Clientes\Frango\login_chk.php:9) in E:\Plets\Clientes\Frango\login_chk.php on line 17

O que pode ser?? tentei varias coisas!

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Tenta...

if (!$linhas == 0){
session_start();
$_SESSION['logado']="$varnome";
header("location:admin.php?login=$varnome");
exit;
}
else
{
header("location:index.php");
exit;
}

Edited by blood
Link to comment
Share on other sites

  • 0

Tenta colocar o mysql_result no teste logico !

<?php
$varnome = "";
$varlogin=$_POST['login'];
$varsenha=$_POST['senha'];
$conex=mysql_connect("localhost","","")or die("Erro ao conectar-se ao servidor My SQL.");
//linha para executar ao servidor My SQL
$bd=mysql_select_db("proc",$conex)or die("Erro ao conectar-se à base de dados.");
$resultado=mysql_query("select * from user where login='$varlogin' and senha='$varsenha'");
$linhas=mysql_num_rows($resultado);
if ($linhas > 0){
$varnome=mysql_result($resultado,0,'nome');
session_start();
$_SESSION['logado']="$varnome";
header("location:admin.php?login=$varnome"); 
}
else
{
header("location:index.php"); 
}
?>

Abraços

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      651.8k
×
×
  • Create New...