Page 1 of 1

Login

Posted: Fri Mar 02, 2012 2:29 am
by gamingmv
When i try to login it always says "Wrong username or password.Try Again" and i am getting mad at it. This is my coding:
authenticate:

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

Code: Select all

<form method="POST" action="authenticate.php">
Username:<input type = "text" name = "player" size = "21"  /><br />
Password:<input type "password" name ="password" size = "21" mask = "x"  /><br />

<input type="submit" value="login" name="submit" />

Re: Login

Posted: Fri Mar 02, 2012 4:22 am
by SpiritWebb
In your login, you forgot the = sign in the password field, it should be

Code: Select all

Password: <input type="password" name="password" size="21" mask="x" /><br />

Re: Login

Posted: Fri Mar 02, 2012 8:15 am
by Chris
There are quite a lot of people have come with the same issue, if they allow logging in without the password it seems to work. Could you show us the structure of your players table?

Re: Login

Posted: Fri Mar 02, 2012 6:13 pm
by hallsofvallhalla
make sure your password field in DB is at least 32 characters

Re: Login

Posted: Fri Mar 02, 2012 10:06 pm
by gamingmv
Thanks for responding halls, I got it fixed, but now its something wrong with my attack.php

Code: Select all



<?php
include 'connect.php';
session_start();
?>

<?php
  $query = "SELECT MAX(`id`) FROM players";
  $result = mysql_query($query) or die("Could not query players");
  $result2 = mysql_fetch_array($result);
  echo "<center>There are is currently " . $result2['MAX(`id`)'] . " registered users.</center>";
?>

><?php

if (isset($_SESSION['player']))
{
	$player=$_SESSION['player'];	
} else {
echo "Not Logged In";
exit;	
}
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);

if (isset($_GET['creature']))
{
$creature=$_GET['creature'];
$creatureinfo="SELECT * from creatures where name = '$creature'";
$creatureinfo2=mysql_query($creatureinfo) or die("could not get the creature you were fighting!");
$creatureinfo3=mysql_fetch_array($creatureinfo2);

}
else
{
  echo "<a href='battle.php'>No Creature selected. Go Back!";
  exit;
}

$playerhp = $playerinfo3['hpoints'];
$playerattack = $playerinfo3['attack'];
$playerdefense = $playerinfo3['defense'];

$creature = $creatureinfo3['name'];
$creaturehp = $creatureinfo3['hpoints'];
$creatureattack = $creatureinfo3['attack'];
$creaturedefense = $creatureinfo3['defense'];


///////////////////////players turn////////////////////

echo "<u> " . $playerinfo3['name'] . "'s Attack</u><br>";
$playerattack = rand(1,20) + $playerattack;
$creaturedefense = rand(1,20) + $creaturedefense;

echo $playerinfo3['name'] . "'s Attack roll is " . $playerattack . "<br>";
echo $creature . "'s defense roll is " . $creaturedefense. "<br>";

if ($playerattack  > $creaturedefense)
{
  echo $playerinfo3['name'] . " hits! <br>";
  $playerdamage = rand(1,6);
   $newcreaturehp = $creaturehp - $playerdamage;
  echo "For " . $playerdamage . " points of damage. <br>";
   if ($newcreaturehp < 1)
   {
     echo "The " . $creature . " has been killed";
      if ($playerinfo3['level'] > $creatureinfo3['level'])
	  {
		$firstmod = $playerinfo3['level'] - $creatureinfo3['level'];
		$secondmod = $firstmod * 10 ;
		if ($seondmod >= 90)// {$secondmod = 90;}
		$thirdmod = ($secondmod / 100) * $creatureinfo3['exper'];
		$totalexpert = $creatureinfo3['exper'] + $thirdmod;
	  }
	  
	  echo"<br /><br /><br /> <B> You Gain " . $totalexpert . "experience.</b><br>";
	  $updateplayer = "update players set exper=exper+'$totalexpert' where name='$player'";
	  mysql_query($updateplayer) or die ("Can't find player");
	  
      echo "<a href='battle.php'>Go Back";
      exit;
   }
  $updatecreature="update creatures set hpoints='$newcreaturehp' where name='$creature' limit 1";
  mysql_query($updatecreature) or die("Could not update creature");
}
else
{
   echo $playerinfo3['name'] . " misses!<br>";
}
//////////////////////creatures turn //////////////////

echo "<u> " . $creature . "'s Attack</u><br>";
$creatureattack = rand(1,20) + $creatureattack;
$playerdefense = rand(1,20) + $playerdefense;

echo $creature . "'s Attack roll is " . $creatureattack . "<br>";
echo $playerinfo3['name'] . "'s defense roll is " . $playerdefense . "<br>";

if ($creatureattack  > $playerdefense)
{
  echo $creature . " hits! <br>";
  $creaturedamage = rand(1,6);
   $newplayerhp = $playerhp - $creaturedamage;
   echo "For " . $creaturedamage . " points of damage. <br>";
   if ($newplayerhp < 1)
   {
     echo $playerinfo3['name'] . " has been killed<br>";
      echo "<a href='gameover.php'>Continue";
      exit;
   }
  $updateplayer="update players set hpoints='$newplayerhp' where name='player1'";
  mysql_query($updateplayer) or die("Could not update player");
}
else
{
  echo $creature . " misses!";
}
echo "<br><br><a href='battle.php?creature=$creature'>Battle Again!";
?>
errors:

Notice: Undefined variable: totalexpert in C:\xampp\htdocs\Game\attack.php on line 79

Notice: Undefined variable: totalexpert in C:\xampp\htdocs\Game\attack.php on line 80

Re: Login

Posted: Fri Mar 02, 2012 10:52 pm
by gamingmv
nvm some how my hole project got corrupt and deleted everything FML