Page 1 of 1

login problem

Posted: Fri Jul 22, 2011 11:53 pm
by dust1031
hey im still a noob at coding, but im getting the hang of it. but when i make a registration page, and type my information in, it creates my account but when i go to my login page it says "invalid Username Or password what am i doing wrong. i think its something with my authenticate page. can someone please take a look at it. its hard trying to test something and not being able to log in.


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='$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='index.php'>Continue</a></big>";
  }
  else
  {
   echo "<big>Wrong username or password.<A href='login.php'>Try Again</a></big>";
  }
}
?>

Re: login problem

Posted: Sat Jul 23, 2011 12:25 am
by Jackolantern
Are you sure you have all of the column names correct in your SQL statement? This is a pretty simple script, and I am not seeing any problems with it. If everything is straight in the SQL, it may be a problem elsewhere.

However, I have not had much sleep, so it could be slipping right past me :P

Re: login problem

Posted: Sat Jul 23, 2011 12:31 am
by Xaleph
add this above the include "connect.php";

error_reporting(E_ALL);
ini_set("display_errors", true);

And, at the bottom of your page:

if(mysql_error()){
print_r(mysql_error();
}

Re: login problem

Posted: Sat Jul 23, 2011 12:37 am
by dust1031
where exactly do i put
if(mysql_error()){
print_r(mysql_error();
}

whenever i put it at the very bottom it comes up syntax error

Re: login problem

Posted: Sat Jul 23, 2011 1:09 am
by Xaleph
Well, that`s a good thing, really. But show us the errors too.

And you can decide where to put it, as long as it is AFTER you finish your queries. Because that function(mysql_error()) returns any SQL errors it found.
And, i see i made an error. Do this:

if(strlen(mysql_error()>0){
print_r(mysql_error());
}

Anyway, you`ll figure it out right? It`s PHP so it should be in pHP tags somewhere.. :)