Anything wrong?[resolved]

Location of the Videos
Post Reply
User avatar
srachit
Posts: 291
Joined: Sat Jan 05, 2013 6:10 pm

Anything wrong?[resolved]

Post by srachit »

This is my authenticate.php, I cant seem to find anything wrong with it, but it isnt displaying any welcome text or wrong password text :/

Code: Select all

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

if (isset($_POST['Login']))
{
  $player=$_POST['name'];
  $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=index.php>Continue</a></big>";
  }
  else
  {
   echo "<big>Wrong username or password.<A href=login.php>Try Again</a></big>";
  }
}
?>
User avatar
Elvar
Posts: 86
Joined: Sun Oct 07, 2012 7:04 pm

Re: Anything wrong?

Post by Elvar »

Hallo scrachit.

First thing, in your query, you are testing for Username, and Password, or are you?

Code: Select all

$query = "select name,password from players where name='$player' and '$password'"; 

"where name='$player'" <-- Seems legit
"and '$password'" <-- does not.

What you are actually doing here, is testing $password whether it's TRUE or FALSE, and since the variable is initialized, testing a string will always yield TRUE. I suppose you want to alter this to password = '$password'.

But there may be another error in your sql, try printing mysql_error() in your "die()" function.
User avatar
srachit
Posts: 291
Joined: Sat Jan 05, 2013 6:10 pm

Re: Anything wrong?

Post by srachit »

Elvar wrote:Hallo scrachit.

First thing, in your query, you are testing for Username, and Password, or are you?

Code: Select all

$query = "select name,password from players where name='$player' and '$password'"; 

"where name='$player'" <-- Seems legit
"and '$password'" <-- does not.

What you are actually doing here, is testing $password whether it's TRUE or FALSE, and since the variable is initialized, testing a string will always yield TRUE. I suppose you want to alter this to password = '$password'.

But there may be another error in your sql, try printing mysql_error() in your "die()" function.
I had originally written it as password = '$password' but it wasnt working, so i checked up halls tutorial and found that he had not put it as password = '$password', so not sure which one is correct.
dbest
Posts: 109
Joined: Sun Nov 20, 2011 12:24 pm

Re: Anything wrong?

Post by dbest »

Can you dump (print_r, if i remember correctly) the "$result2" variable on the screen?
User avatar
OldRod
Posts: 1320
Joined: Sun Sep 20, 2009 4:26 pm

Re: Anything wrong?

Post by OldRod »

This is an ongoing problem with this tutorial.

Change this:
$query = "select name,password from players where name='$player' and '$password'";
to this:
$query = "select name,password from players where name='$player' and password='$password'";
User avatar
srachit
Posts: 291
Joined: Sat Jan 05, 2013 6:10 pm

Re: Anything wrong?

Post by srachit »

OldRod wrote:This is an ongoing problem with this tutorial.

Change this:
$query = "select name,password from players where name='$player' and '$password'";
to this:
$query = "select name,password from players where name='$player' and password='$password'";
Changed, it still takes me to a blank authenticate.php page

Also tried the print_r as suggested earlier, still a blank page and nothing got printed
User avatar
srachit
Posts: 291
Joined: Sat Jan 05, 2013 6:10 pm

Re: Anything wrong?

Post by srachit »

Just put some echo statements through the program and noticed that it isnt entering the if statement only, anyone can spot anything wrong?
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: Anything wrong?

Post by hallsofvallhalla »

you issue is stemming from the post method on the login page. Check it is actually setting the post variable and it is spelled right.

Code: Select all

if (isset($_POST['Login']))
User avatar
srachit
Posts: 291
Joined: Sat Jan 05, 2013 6:10 pm

Re: Anything wrong?

Post by srachit »

hallsofvallhalla wrote:you issue is stemming from the post method on the login page. Check it is actually setting the post variable and it is spelled right.

Code: Select all

if (isset($_POST['Login']))
I had already correct this yesterday and it still wasnt working.
I checked my login.php file and there was something missing there that is why it wasnt working, thanks to everyone who helped :)
Post Reply

Return to “Older Browser MMO Videos”