login problem

C++, C#, Java, PHP, ect...
Post Reply
dust1031
Posts: 92
Joined: Fri Jul 22, 2011 3:38 am

login problem

Post 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>";
  }
}
?>
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: login problem

Post 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
The indelible lord of tl;dr
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: login problem

Post 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();
}
dust1031
Posts: 92
Joined: Fri Jul 22, 2011 3:38 am

Re: login problem

Post 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
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: login problem

Post 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.. :)
Post Reply

Return to “Coding”