need help with battle.php

Location of the Videos
Post Reply
maggnetic
Posts: 14
Joined: Sat Dec 31, 2011 2:44 am

need help with battle.php

Post by maggnetic »

I need help with my battle.php every time i go to localhost/tutorial/battle.php IT says could not select player status!

this is my battle.php

Code: Select all

<?php
include_once '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 player where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die ("could not select player status!");
$playerinfo3=mysql_fetch_array($playerinfo2);

$playerhp = $playerinfo3['hpoints'];
$playerattack = $playerinfo3['attack'];
$playerdefence = $playerinfo3['defence'];

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'];
$creaturedefence = $creatureinfo3['defence'];

/////player info
echo "<u>" . $playerinfo3['name'] . "</u><br>";
echo "hit points = " . $playerhp . "<br>";
echo "attack = " . $playerattack . "<br>";
echo "defence = " . $playerdefence . "<br><br><br>";

///////creature info
echo "<u>" . $creatureinfo['name'] . "</u><br>";
echo "hit points = " . $creaturehp . "<br>";
echo "attack = " . $creatureattack . "<br>";
echo "defence = " . $creaturedefence . "<br><br><br>";

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

?>
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

Re: need help with battle.php

Post by Torniquet »

make sure you have the table name right and the fields match and are spelt correct
New Site Coming Soon! Stay tuned :D
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: need help with battle.php

Post by hallsofvallhalla »

$playerinfo="select * from player where name='$player'";
should be

Code: Select all

$playerinfo="select * from players where name='$player'";
u forgot the s
maggnetic
Posts: 14
Joined: Sat Dec 31, 2011 2:44 am

Re: need help with battle.php

Post by maggnetic »

okay thanks you for the help but now i have two other problems the first one is the every time i go to localhost/tutorial/battle.php i see this

S <<<<<<<<<<<<<<<<< the creatures name is S
Hit points = 5
Attack = 3
Defence = 3

the problem is the name i dont know where i whent wrong pls help

Also every time i press Attack! i get an error msg saying this:
(!) Parse error: syntax error, unexpected '/' in C:\wamp\www\tutorial\attack.php on line 25

and this is line 25

Code: Select all

if (isset($_GET['creatures']))
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Re: need help with battle.php

Post by Callan S. »

Code: Select all

echo "<u>" . $creatureinfo['name'] . "</u><br>";
should be

Code: Select all

echo "<u>" . $creatureinfo3['name'] . "</u><br>";
or ideally

Code: Select all

echo "<u>" . $creature . "</u><br>";
since further up you made $creature equal $creatureinfo3['name']

Not sure about the syntax thing? I summon jackolantern! *throwing down a smoke bomb as I speak*
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: need help with battle.php

Post by Jackolantern »

Huh? Wha? How did I get here? -looks around-

Sorry, what was the question? Is there a problem with the syntax? Unless I am mistaken, it looks covered.
The indelible lord of tl;dr
Winawer
Posts: 180
Joined: Wed Aug 17, 2011 5:53 am

Re: need help with battle.php

Post by Winawer »

maggnetic wrote: (!) Parse error: syntax error, unexpected '/' in C:\wamp\www\tutorial\attack.php on line 25
Post your attack.php
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: need help with battle.php

Post by Jackolantern »

Winawer wrote:
maggnetic wrote: (!) Parse error: syntax error, unexpected '/' in C:\wamp\www\tutorial\attack.php on line 25
Post your attack.php
Definitely. Please do post the attack.php script, Maggnetic. Although it says "Line 25", we won't be able to help you with just that one line (although it helps that we know what line 25 is, since we don't have line numbers here). In fact, it usually isn't the line number they give. It is often a line or two above the flagged line number!
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: need help with battle.php

Post by hallsofvallhalla »

anytime you see somehting post a "s" it usually means you are missing the 3 after the query variable.

Definitely need to see your code
maggnetic
Posts: 14
Joined: Sat Dec 31, 2011 2:44 am

Re: need help with battle.php

Post by maggnetic »

okay well this is my Attack.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);

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=msql_fetch_array($creatureinfo2);

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

  $playerhp = $playerinfo3['hpoint'];
  $playerattack = $playerinfo3['attack'];
  $playerdefence = $playerinfo3['defence'];

 $creature = $creatureinfo3['name'];
 $creaturehp = $creatureinfo3['hpoints'];
 $creatureattack = $creatureinfo3['attack'];
 $creaturedefence = $creatureinfo3['defence'];


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

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

echo $playerinfo3['name'] . "'s attack roll is " . $playerattack . "<br>";
echo $creature . "'s defence roll is " . $creaturedefence . "<br>";

if ($playerattack > $creaturedefence)
{
  echo $playerinfo3['name'] . " hits! <br>";
  $playerdamage = ran(1,6);
   $newcreaturehp = $creaturehp - $playersdamage;
  echo "for "  .  $playerdamage. " points damage. <br>";
  if ($newcreaturehp < 1)
  {
    echo "The " . $creature . " has been killed";

       $updatecreature="select from creatures where name='$creature' limit 1";
 mysql_query($updatecreature) or die ("could not update creature");



     /////////////////////////video6////////////////////////
     if ($playerinfo3['level'] > $creatureinfo3['level'];

     $firstmod = $playeringo3{'level'] - $creatureinfo3['level'];
     $secondmod = $firstmod = 10 ;
     if ($secondmod>90)($secondmod = 90);
     $thirdmod = ($secondmod / 100) * $creatureinfo3 ['exper'];
     $totalplayer = $creatureinfo3['exper'] = $thirdmod;
  }
  else
  {
    $firstmod = $creatureinfo3['level'] - $playerinfo3['level'];
    $secondmod = $firstmod = 10;
    if ($secondmod > 90)($secondmod = 90);
    $thirdmod = ($secondmod / 100 ) * $creatureinfo3['exper'];
    $totalexper = $creatureinfo3['exper'];
  }
     $totalexper = (int) $totalexper;

        echo "<br><b><big>You Gain " . $totalexper . " experiance.</b></big></br>";
   $updateplayer="update player set exper'exper+'$totalexper' where name='$player'";
 mysql_query($updateplayer) or die ("could not update player");



  echo "<a href='battle.php>Go Back";
  exit;
  }
  /////////////////////////
  $epdatecreature="update creature set hpoints='$newcreaturehp' where name='$creature' limit 1";
  mysql_query($updatecreature) or die ("could not update creature");
}
else
{
  echo $playerinfo3['name'] . "misses!<br>";
}
//////////////////////creature turn ///////////////////////

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

if  ($creatureattack > $playerdefence)
{
  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 hpoint='$newplayerhp' where name='$player'";
   mysql_query($updateplayer) or die ("Could not update player");
}
else
{
  echo $creature . "misses!";
}
echo "<br><br><a href='battle.php?creature=$creature>Battle Again!";
?>
Post Reply

Return to “Older Browser MMO Videos”