Problem with register/login system - qustion for howell

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
kibo95
Posts: 35
Joined: Wed Jul 16, 2014 6:59 am

Problem with register/login system - qustion for howell

Post by kibo95 »

Hi everybody
I have problems with my register/login system
I watched Howell's tutorial on Youtube about making MMORPG
i did everything like he did,and it looks like everything works just fine
but I realised that i have problem with register/login system.
Here is explanation of the problems
Register works just fine,but when i try to login,for some passwords it just says that i typed wrong username of password (that's impossible,i tried many,many times)
I noticed that some passwords works fine,but with some of them i just can't login
so i tried different combinations:

Username | password
player1 | pass1 -works
player2 | pass2 -doesn't work
player3 | pass3 -works
player4 | pass4 -doesn't work
player5 | pass5 -doesn't work
player6 | pass6 -doesn't work
player7 | pass7 -works

I also notied that if i delete those players from database and register again with different combination,this happens
pass7 works for all these nicks,and pass2 doesn't work with any of these nicks,so it depends on passwords is it going to work or not
I'm really confused,don't understand why is this happening
I need your help,here is the code of "authenticate.php",that decide,whether username and password match with those in database

Code: Select all

<?php
include_once 'connect.php';
session_start();

if (isset ($_POST['submit']))
{
$player=$_POST['player'];
$password=$_POST['password'];
$player=strip_tags($player);
$password=strip_tags($password);
$password=md5($password);

$query = "Select name,password from players where name='$player' and '$password'";
$result = mysql_query ($query) or die ("Could not query players");
$result2 = mysql_fetch_array($result);
if ($result2)
{
$_SESSION['player']=$player;

echo "<big>Logged in successfully<br>";
echo "<A href='battle.php'>Continue</a></big>";

}
else
{
echo "<big>Wrong username or password.<A href='login.php'>Try again</a></big>";
}
}
?>
User avatar
OldRod
Posts: 1321
Joined: Sun Sep 20, 2009 4:26 pm

Re: Problem with register/login system - qustion for howell

Post by OldRod »

Change this:

Code: Select all

$query = "Select name,password from players where name='$player' and '$password'";
to this:

Code: Select all

$query = "Select name,password from players where name='$player' and password='$password'";
User avatar
kibo95
Posts: 35
Joined: Wed Jul 16, 2014 6:59 am

Re: Problem with register/login system - qustion for howell

Post by kibo95 »

I did not see that :O
thanks! :D
it should work fine now
btw great forum,great people :D
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Problem with register/login system - qustion for howell

Post by hallsofvallhalla »

yep that is a gotcha for everyone. :)


Thanks!
Post Reply

Return to “Beginner Help and Support”