Browser MMO Video #5

Location of the Videos
Post Reply
herko125
Posts: 17
Joined: Fri Oct 16, 2009 3:12 pm

Re: Video#5

Post by herko125 »

okay...so i got a problem
i looked on the otehr 4pages and tried all the fixes u guys said
but it wont work

its battle.php

Code: Select all

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

if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
}


$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);

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

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
{
$creatureinfo="SELECT * from creatures order by rand() limit 1";
$creatureinfo2=mysql_query($creatureinfo) or die("could get a creature!");
$creatureinfo3=mysql_fetch_array($creatureinfo2);
}

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

/////player info
echo "<u> " . $playerinfo3['name'] . "</u><br>";
echo "Hit points = " . $playerhp . "<br>";
echo "Attack = " . $playerattack . "<br>";
echo "Defense = " . $playerdefense . "<br><br><br>";

///////creature info
echo "<u> " . $creatureinfo3['name'] . "</u><br>";
echo "Hit points = " . $creaturehp . "<br>";
echo "Attack = " . $creatureattack . "<br>";
echo "Defense = " . $creaturedefense . "<br><br><br>";

echo "<a href='attack.php?creature=$creature'>Attack!";

?>
like...can some1 tell me why this isnt woorking??
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video#5

Post by hallsofvallhalla »

what is the error you are getting?
herko125
Posts: 17
Joined: Fri Oct 16, 2009 3:12 pm

Re: Video#5

Post by herko125 »

Notice: Undefined variable: player in C:\wamp\www\battle.php on line 11
thats the error

and second is....that when i try to login with existing usrname and password it says that the username or pw is wrong x.x
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video#5

Post by hallsofvallhalla »

Its not saving your session.


after this

Code: Select all

if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
}
add this

Code: Select all

else
{
echo "You are not logged in. <a href='login.php'>Login";
exit;
}
there is something screwy with the username and password fields in the first videos, post your register and your reguser.php code...
herko125
Posts: 17
Joined: Fri Oct 16, 2009 3:12 pm

Re: Video#5

Post by herko125 »

okay

register.php

Code: Select all

<?php
include 'connect.php';

?>

<form method="post" action="reguser.php">
Type Username Here: <input type="text" name="player" size="21"><br>
Type Password Here: <input type="password" name="password" size="15"><br>
Retype password:  <input type="password" name="pass2" size="15"><br>
Type E-mail address: <input type="text" name="email" size="60"><br>
<input type="submit" value="submit">
</form>
reguser.php

Code: Select all

<?php
include 'connect.php';
?>

<?php
$player=$_POST['player'];
$password=$_POST['password'];
$pass2=$_POST['pass2'];
$player=strip_tags($player);
$email=$_POST['email'];
$email=strip_tags($email);

if ($email == "")
{
echo "You didn't enter a email address!<br>";
echo " <A href='register.php'>Go back</a>";
    exit;
    }
if ($password==$pass2)
{
 
  $isplayer="SELECT * from players where name='$player'";
  $isplayer2=mysql_query($isplayer) or die("Could not query players table");
  $isplayer3=mysql_fetch_array($isplayer2);
  if(!$_POST['password'] || !$_POST['pass2'])
  {
     print "You did not enter a password";
    echo " <A href='register.php'>Go back</a><br>";
    exit;
  }
  else if($isplayer3 || strlen($player)>15 || strlen($player)<1)
  {
     print "There is already a player of that name or the name you specified is over 16 letters or less than 1 letter<br>";
     echo " <A href='register.php'>Go back</a>";
    exit;
  }
  else
  {
    $isaddress="SELECT * from players where email='$email'";
    $isaddress2=mysql_query($isaddress) or die("not able to query for password");
    $isaddress3=mysql_fetch_array($isaddress2);
    if($isaddress3)
    {
      print "There is already a player with that e-mail address<br>";
      echo " <A href='register.php'>Go back</a>";
    exit;
    }
    else
    {
        $password=md5($password);
       
$SQL = "INSERT into players(name, password, email, level, exper) VALUES ('$player','$password','$email','1','0')";
      mysql_query($SQL) or die("could not register");
     
      print "Thank you for registering.";
   
    }
  }
}

else
{
  print "Your password didn't match or you did not enter a password<br>";
   echo " <A href='register.php'>Go back</a>";
    exit;
}
echo "<br><A href='login.php'>Login Page</a>";
?>
login.php (just incase)

Code: Select all

<form method="POST" action="authenticate.php">
User Name <input type="text" name="player" size="21">
Password <input type="password" name="password" size="21">
<input type="submit" value="Login" name="submit">
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video#5

Post by hallsofvallhalla »

lets see the authenticate.php too.
herko125
Posts: 17
Joined: Fri Oct 16, 2009 3:12 pm

Re: Video#5

Post by herko125 »

okay

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
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video#5

Post by hallsofvallhalla »

change this

Code: Select all

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

Code: Select all

$query = "select name,password from players where name='$player' and password = '$password' ";
herko125
Posts: 17
Joined: Fri Oct 16, 2009 3:12 pm

Re: Video#5

Post by herko125 »

works now tnx Halls!

*edit*

so now when i login with an account named testing and I attack the creature....
the testing dont fight with Goblin...but player1 dose...
even if im not logged in with it...
so i tried changing this piece of code

Code: Select all

$playerinfo="SELECT * from players where name='player1'";
to

Code: Select all

$playerinfo="SELECT * from players where name='$players'";
i get an error
Notice: Undefined variable: players in C:\wamp\www\attack.php on line 7
and line 7 is this code....what is the problem...?


*edit2*
hehe i fixed (:
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video#5

Post by hallsofvallhalla »

awesome. The more trouble you have and fix it the better you become.
Post Reply

Return to “Older Browser MMO Videos”