Browser MMO Video #5

Location of the Videos
bradders0906
Posts: 9
Joined: Sat May 05, 2012 2:04 pm

Re: Video#5

Post by bradders0906 »

thanks i fixed that problem, now im getting a different error, this is when im logged in and try to attack:

Parse error: syntax error, unexpected ')' in C:\wamp\www\tutorial\attack.php on line 7

my attack code is:

Code: Select all

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

if (isset($_SESSION['player']))
(
$player=$SESSION['player']))
)
else
(
 echo "Not Logged in <br><br> <A href=' login.php'>Login</a>";
 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 defeated";
       
        $updatecreature="DELETE from creatures where name='$creature' limit 1";
  mysql_query($updatecreature) or die("Could not update creature");
      
      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!";
?>
bradders0906
Posts: 9
Joined: Sat May 05, 2012 2:04 pm

Re: Video#5

Post by bradders0906 »

.
bradders0906
Posts: 9
Joined: Sat May 05, 2012 2:04 pm

Re: Video#5

Post by bradders0906 »

i restarted the whole project again, im up to this part at the end, can somebody send me their whole authenticate.php code please?, mines coming up with this error Parse error: syntax error, unexpected ';' in C:\wamp\www\game\authenticate.php on line 7

heres my code if you want to check

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 of password.<A href='login.php'>Try Again</a></big>";
  }
)
?>    
thanks for your help
Zoo
Posts: 21
Joined: Tue Apr 17, 2012 6:38 pm

Re: Video#5

Post by Zoo »

Check error, it sayed something wrong with ')' so:
should be:

Code: Select all

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

if (isset($_SESSION['player']))
{
$player=$SESSION['player']))
}
else
{
echo "Not Logged in <br><br> <A href=' login.php'>Login</a>";
exit;
}
and the same problem in authenticate.php change ( to {
should be work
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video#5

Post by hallsofvallhalla »

and look at

Code: Select all

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

Code: Select all

 $query = "select name, password from players where name='$player' and password = '$password'";
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: Video#5

Post by Jackolantern »

Is the "and $password" part still in the video Halls (not sure where that code was added or I would check)? Maybe if it is you could add annotations?
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video#5

Post by hallsofvallhalla »

yeah will do that.
Mousedog
Posts: 1
Joined: Wed Nov 12, 2014 2:44 pm

Re: Browser MMO Video #5

Post by Mousedog »

Hi i have followed all your instructions up to Browser Based MMORPG Video 5 but when i log in it says successfully looged in and when i click continue it says your are not logged in please help what have i done wrong
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Browser MMO Video #5

Post by Epiales »

Mousedog wrote:Hi i have followed all your instructions up to Browser Based MMORPG Video 5 but when i log in it says successfully looged in and when i click continue it says your are not logged in please help what have i done wrong
Can you please post u're code so we can see? login.php and maybe even register/signup.php? and if an authenticate.php too

Also check in u're Authenticate.php this line of code:

Code: Select all

  $query = "select name,password from players where name='$player' and '$password'";
If it has not been corrected, change it to this:

Code: Select all

$query = "select name,password from players where name='$player' and password = '$password'";
Nothing fancy, but a work in progress!

http://gameplaytoday.net
Post Reply

Return to “Older Browser MMO Videos”