FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Login problem





ranzon
i'm trying to get n0obie4life's login script to work, but when i try to log in, i just get that the password is wrong.

and this is how the script looks:
Code:
<?php

$username = $_POST['username'];
$password = $_POST['password'];

include("db.php");

$sql = "SELECT * FROM ansatte WHERE nick = '$username'";
$result = mysql_query($sql);

if (!$result)
{
   die (mysql_error());
}
$num_rows = mysql_num_rows($result);

if ( $num_rows == '3' )
{
   die ('Invalid Username!');
   exit;
}
else
{
   $row = mysql_fetch_row($result);
   
   if ( $password == $row[4] )
   {
      echo ' Logged in ! ';
   }
   else
   {
      echo 'Wrong password.';
      exit;
   }
}

?>

my database structure:
ID
lastname
firstname
nick <-- wich is the username
password
level <-- for acess levels
age

please help me.. Wink
AftershockVibe
Quote:
$num_rows == '3'


Why are you looking for rows == '3' ? Surely if you're looking for an invalid username this would be rows != 1 ? And why would it be in quotes?!

Other than that everything looks ok. The one thing it might be is if your MySQL table rows aren't numbered in the sequence you typed out.

Try the following instead. indexing by row is usually a bad idea:
Code:
<?php

$username = $_POST['username'];
$password = $_POST['password'];

include("db.php");

$sql = "SELECT nick, password FROM ansatte WHERE nick = '" . $username . "'";
$result = mysql_query($sql) or die("Unable to execute query!");


$num_rows = mysql_num_rows($result);

if ( $num_rows != 1 )
{
   echo 'Invalid Username!';
}
else
{
   $row = mysql_fetch_assoc($result);
   
   if ( $password == $row['password'] )
   {
      echo ' Logged in ! ';
   }
   else
   {
      echo 'Wrong password.';
   }
}

?>
Related topics
Dirrect Admin Login Problem
PHP Login Problem
PhpBB Login Problem Please help me
DirectAdmin login Problem
Login Bug in Joomla 1.0.8
Invalid login problem
FTP Login Problem..
IMAP Problem
Login problem
Login problem
Knight online login problem
Post value from one site to another site.
Login Problem
FriHost PHP login problem
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.