Using Magic

Location of the Videos
Post Reply
Cold|Drawn
Posts: 17
Joined: Sat Jan 16, 2010 12:03 am

Using Magic

Post by Cold|Drawn »

Hi, it's me again. Sorry for the double thread but I have another question.

Under tutorial 13, using magic.

I am getting these 2 errors

Notice: Undefined variable: pid in C:\wamp\www\tutorial\attack.php on line 63

Notice: Undefined variable: playerpass in C:\wamp\www\tutorial\attack.php on line 91

I am guessing both of this variables are defined in battle / usemagic.php correct?

Code: Select all

Battle.php
<?php
include_once 'connect.php';
session_start();
include_once 'logo.php';
?>

<link href="style.css" rel="stylesheet" type="text/css" />
<div id="login2" div align="center">

<?php

if (isset($_SESSION['player']))
{
   $player=$_SESSION['player'];
}
else
{
    echo "Not logged in <br><br><A href='login.php'>Login</a>";
    exit;
}
?>
</div>


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

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

//////////Items//////////
if (isset($_GET['randid']))
{
   $randid=$_GET['randid'];
   $iteminfo="SELECT * from inventory where randid='$randid'";
   $iteminfo2=mysql_query($iteminfo) or die ("Could not retrieve item stats!");
   $iteminfo3=mysql_fetch_array($iteminfo2);

if (!$iteminfo3['name'])
{
}

else
{
    $name = $iteminfo3['name'];
    $stats = $iteminfo3['stats'];
    $statadd = $iteminfo3['statadd'];
    $type = $iteminfo3['type'];
}

if ($type == "healing")
{
    $newhp = $statadd + $playerhp;
    if ($newhp > $playerinfo3['maxhp'])
    {
       $newhp = $playerinfo3['maxhp'];
    }
    
    $updateplayer="update players set hpoints='$newhp' where name='$player'";
    mysql_query($updateplayer) or die ("Could not update player");
    
    $updateitem="DELETE from inventory where name='$name' AND randid='$randid' limit 1";
    mysql_query($updateitem) or die ("Could not delete item");
    
    $playerhp = $newhp;

    echo "Used " . $name . " and recovered " . $statadd . ".<br>";
}
}

//////////Creatures//////////
$creature = $playerinfo3['creature'];

if ($creature !=0)
{
   $creatureinfo="SELECT * from creatures where id = '$creature'";
   $creatureinfo2=mysql_query($creatureinfo) or die ("could not get creature you are fighting!!");
   $creatureinfo3=mysql_fetch_array($creatureinfo2);
}

else
{
    $creatureinfo="Select * from creatures order by rand() limit 1";
    $creatureinfo2=mysql_query($creatureinfo) or die ("could not get a creature!");
    $creatureinfo3=mysql_fetch_array($creatureinfo2);
    $cid = $creatureinfo3['id'];
    $updateplayer="update players set creature='$cid' where name='$player'";
    mysql_query($updateplayer) or die ("Could not update player");
}

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


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

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

//////////Attack////////////
echo "<A href='attack.php?creature=$creature'>Attack";

//////////Use Magic/////////
echo "<br><A href='usemagic.php?creature=$creature'>Cast Spell";
//////////Use Item//////////
echo "<br><A href='useitem.php?creature=$creature'>Inventory";
echo "<br><A href='index.php'>Escape!";
?>
</div>

<div id="logout">
<?php
echo "<br><A href='logout.php'><img src='images/logout.gif'>";
?>
</div>

Code: Select all

Use Magic.php
<?php

include_once 'connect.php';
session_start();
include_once 'logo.php';
?>
<link href="style.css" rel="stylesheet" type="text/css" />
<?php

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);
include_once 'statpanel.php';
$playerid = $playerinfo3['id'];
?>
</div>
<div id="table">
<?php

$counter = 0;
echo "<small>";
      print "<center>";
      print "<table border='0' width='70%' cellspacing='20'>";
      print "<tr><td width='25%' valign='top'>";
      print "</td>";
      print "<td valign='top' width='75%'>";
      $invinfo="SELECT * from playermagic where pid='$playerid'";
      $invinfo2=mysql_query($invinfo) or die("could not select player magic");
      print "<table border='1' bordercolor='white' bgcolor='#ffffff'>";
      print "<tr><td>Name<font color='ffffff'>________________</font></td><td>Level<font color='ffffff'>______</td><td>Type<font color='ffffff'>______</td><td>Value<font color='ffffff'>______</td><td>Point Cost<font color='ffffff'>______</td><td><font color='ffffff'>________________</td></tr>";
      while($invinfo3=mysql_fetch_array($invinfo2))
      {
      print "<tr><td>$invinfo3[name]</td><td>$invinfo3[level]</td><td>$invinfo3[type]</td><td>$invinfo3[svalue]</td><td>$invinfo3[scost]</td><td><A href='attack.php?sid=$invinfo3[sid]'>Use Magic</td></tr>";
       $counter = 1;

      }

      print "</table>";
      print "</td></tr></table>";
      print "</center>";
       echo "</small>";

      if ($counter == 0)
      {
            echo "<center>You have no Spells!<br>";
            echo "<a href='battle.php>Go Back</center>";
            exit;
      }

    echo "<center><a href='battle.php>NeverMind</center>";
   
    ?>
    </div>
(I tried downloading the file from the respective thread but mediafire is linking me to its home webpage)
bear with me, I am very new in this.

Thanks a lot guys :)
Cold|Drawn
Posts: 17
Joined: Sat Jan 16, 2010 12:03 am

Re: Using Magic

Post by Cold|Drawn »

Case solved!

downloaded the the psp files from tutorial 14, opened up the attack.php

filled in the 2 variables

$pid = $playerinfo3['id']

and as for playerpass
$playerpass = 0
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Using Magic

Post by hallsofvallhalla »

sorry for my delay in answering. The more popular this site gets the harder it is for me to keep up :)

Glad you solved the problem!
Post Reply

Return to “Older Browser MMO Videos”