Browser MMO Video #7

Location of the Videos
Post Reply
pretender5552
Posts: 127
Joined: Mon Jan 03, 2011 5:38 am

Re: Video#7

Post by pretender5552 »

I am getting a undefined index error for randid online 28

Code: Select all

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

if (isset($_SESSION['players']))
{
   $player=$_SESSION['players'];
}
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 retreieve player stats");
$playerinfo3=mysql_fetch_array($playerinfo2);

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

//////////////////tutorial 7////////////////
if (isset($_GET['randid']));
{
   $randid=$_GET['randid'];
   $iteminfo="SELECT * from inventory where randid='$randid'";
$iteminfo2=mysql_query($iteminfo) or die("could not get 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['maxhitpoints'])
   {
    $newhp = $playerinfo3['maxhitpoints'];
   }
    $updateplayer="update players set hitpoints='$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>";
}

}}
///////////////////////////////////////



 if (isset($_GET['creatures']))
{
   $creature=$_GET['creatures'];
   $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("couldn't get a creature!");
$creatureinfo3=mysql_fetch_array($creatureinfo2);
}

 $creature = $creatureinfo3['name'];
 $creaturehp = $creatureinfo3['hitpoints'];
 $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?creatures=$creature'>Attack!";
 
 ////////////////////////////tutorial7///////////////////
 echo "<br><a href='useitem.php?creature=$creature'>Inventory";
 echo "<br><a href='store.php?creature=$creature'>Store";

 ?>
And a undefined index error for creatures in line 15

Code: Select all

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

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

$creature=$_GET['creatures'];

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

$playerid = $playerinfo3 ['id'];

$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 inventory where id='$playerid'";
     $invinfo2=mysql_query($invinfo) or die("could not select player inventory");
     print "<table border='1' bondercolor='white' bgcolor='#ffffff'>";
     print "<tr><td>Name<font color='ffffff'>________________</font></td><td>Stat<font color='ffffff'>______</td><td>Stat Add<font color='ffffff'>________________</td></tr>";
     while($invisfo3=mysql_fetch_array($invinfo2))
     {
     print "<tr><td>$invinfo3[name]</td>$invinfo3[stats]</td>
<td>$invfo3[statadd]</td><td>$invinfo3[tupe]</td><td><a href='battle.php?
randid=$invinfo3[randid]&creature=$creature'>Use Item</td></tr>";
       $counter = 1;
       
       
       }
       
       print "</table>";
       print "</td></tr></trable>";
       print "</center>";
        echo "</small>";
        
       if ($counter == 0)
       {
             echo "<center>You have nothing in your inventory!<br>";
             echo "<a href='battle.php?creature=$creature'>Go Back</center>";
             exit;
       }
       
     echo "<center><a href='battle.php?creature=$creature'>Nevermind</center>";
     
     ?>
pretender5552
Posts: 127
Joined: Mon Jan 03, 2011 5:38 am

Re: Video#7

Post by pretender5552 »

Alright I managed to fix the second one but for some reason my message you have nothing in the inventory as well as the go back link is appearing above my table instead of below.
pretender5552
Posts: 127
Joined: Mon Jan 03, 2011 5:38 am

Re: Video#7

Post by pretender5552 »

Alright fixed the randid error, I had an unnecessary semi colon
NDest
Posts: 11
Joined: Tue Feb 01, 2011 12:43 pm

Re: Video#7

Post by NDest »

Hi its me again, so i managed to fix all the errors on php i would have by using NetBeans instead of Context, Netbeans warns you a lot more and indicates the errors without running on your browser and finding the line that has the error.

But now i have a different type of error/bug, well my php are fine so i think the problem is with the database
This is what happens:

You login and i'm on the battle with a creature, so , to try potions i attacked and lost 4 hpoints so I go to a store, all potions that i added by the database appear, but when you try to buy a lets see Minor or other one, it always appears Major Healing Potion Purchased, so i go to inventory and i have only a Major healing Potion, i click use item, it comes back to the battle but it didnt heal and if you go to the inventory again you still have the major potion.

Regards,
NDest

EDIT1: i got the second bug, that wouldn't heal you, finnaly fixed, :D i typed on the database Type = Healing and it should be all lowercase, but i still cant figure the first bug that all potions i buy, it always buys a Major one

EDIT2: baam the second bug is recovered, it wasnt my fault i just deleted the major potion from the store and added new ones and its working
NDest.
Onwer of
Image
a minecaft server
SkeLa
Posts: 1
Joined: Tue Feb 22, 2011 3:40 pm

Re: Video#7

Post by SkeLa »

<?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;
}

$creature=$_GET['creature'];
$randid=$_GET['randid'];

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

$playerid=$playerinfo3['id'];

$iteminfo="SELECT * from store WHERE randid='$randid'";
$iteminfo2= mysql_query($iteminfo) or die ("could not get item stats");
$iteminfo3= mysql_fetch_array($iteminfo2);

$item = $iteminfo3['name'];
$stats = $iteminfo3['stats'];
$statadd = $iteminfo3['statadd'];
$type = $iteminfo3['type'];
$randid2 = rand(1000,999999999);

$itembought = "INSERT into inventory (id, name, stats, statadd, randid, type) VALUES ('$playerid', '$item', '$stats', '$statadd', '$randid2', '$type')";
mysql_query($itembought) or die ("could not store item in backpak");
echo $item . " bought.<br>";
echo "<center><a href='battle.php?creature=$creature'>Go Back</a></center>";
?>

it says the index creature is unidentified :?: :?:
any help??


p.s great tuts you know your way around php and sql better than i know my way to school lol :)


nvm, i moved on with the tutorials, and saw i didnt need it anyway
GirtyZZ
Posts: 1
Joined: Thu May 05, 2011 12:42 pm

Re: Video#7

Post by GirtyZZ »

Hi, I'm new there.
I'm making the game, before this video all errors i had i solved by myself. Now I made inventory and store. It's all good, but all problems are starting at useitem.php . I created the file, copied source, then go bought item, get to use it, but i had error -

Code: Select all

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\AppServ\www\tutorial\useitem.php:1) in C:\AppServ\www\tutorial\useitem.php on line 5

Code: Select all

include_once 'connect.php';
    
Line 5:	session_start();

    if (isset($_SESSION['player']))
    {
      $player=$_SESSION['player'];
Can someone help me. I can still do everything there, but it makes to look ugly my site.
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video#7

Post by hallsofvallhalla »

remove all white spaces or empty lines and place session start at top of page
dust1031
Posts: 92
Joined: Fri Jul 22, 2011 3:38 am

Re: Video#7

Post by dust1031 »

hey i got everything working, no errors at all, but when i buy a item in the store then go to my inventory and click "Use Item" it goes back to battle.php but it doesnt use the item and it doesnt disappear from my inventory. i copied all your codes just like u have them. what is wrong
User avatar
Nexus
Posts: 293
Joined: Sat Jun 18, 2011 10:42 pm

Re: Video#7

Post by Nexus »

Generally if you have a problem you should post the code, then people can help you quickly without having to ask for the code.
dust1031
Posts: 92
Joined: Fri Jul 22, 2011 3:38 am

Re: Video#7

Post by dust1031 »

buy item code

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;
}

  $creature=$_GET['creature'];
  $randid=$_GET['randid'];

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

$playerid = $playerinfo3['id'];

$iteminfo="SELECT * from store where randid='$randid'";
$iteminfo2=mysql_query($iteminfo) or die("could not get item stats!");
$iteminfo3=mysql_fetch_array($iteminfo2);

$name = $iteminfo3['name'];
$stats = $iteminfo3['stats'];
$statadd = $iteminfo3['statadd'];
$type = $iteminfo3['type'];
$randid2 = rand(1000,999999999);

$itembought = "INSERT into inventory(id, name, stats, statadd, randid,type) VALUES ('$playerid','$name','$stats','$statadd','$randid2','$type')";
mysql_query($itembought) or die("could not insert item into backpack");

echo $name . " Purchased";
echo "<center><a href='battle.php?creature=$creature'>Go Back</center>";
  
  
  ?>

store code

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;
}

  $creature=$_GET['creature'];
$counter = 0;

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

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 store where amount > 0";
      $invinfo2=mysql_query($invinfo) or die("could not select anything from the store.");
      print "<table border='1' bordercolor='white' bgcolor='#ffffff'>";
      print "<tr><td>Name<font color='ffffff'>________________</td><td>Stat<font color='ffffff'>______</td><td>Stat Add<font color='ffffff'>______</td><td>Type<font color='ffffff'>______</td><td>Price<font color='ffffff'>______</td></tr>";
      while($invinfo3=mysql_fetch_array($invinfo2))
      {
      $counter = 1;
      print "<tr><td>$invinfo3[name]</td><td>$invinfo3[stats]</td><td>$invinfo3[statadd]</td><td>$invinfo3[type]</td><td>$invinfo3[price]</td><td><A href='buyitem.php?randid=$invinfo3[randid]&creature=$creature'>Buy Item</td></tr>";

      }

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

      if ($counter == 0)
      {
            echo "<center>There is nothing in the store at this time.<br>";
            echo "<a href='battle.php?creature=$creature'>Go Back</center>";
            exit;
      }
  echo "<center><a href='battle.php?creature=$creature'>Never Mind</center>";
  
  ?>
use item code

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;
}

$creature=$_GET['creature'];

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

$playerid = $playerinfo3['id'];

$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 inventory where id='$playerid'";
      $invinfo2=mysql_query($invinfo) or die("could not select player inventory");
      print "<table border='1' bordercolor='white' bgcolor='#ffffff'>";
      print "<tr><td>Name<font color='ffffff'>________________</font></td><td>Stat<font color='ffffff'>______</td><td>Stat Add<font color='ffffff'>______</td><td>Type<font color='ffffff'>______</td><td><font color='ffffff'>________________</td></tr>";
      while($invinfo3=mysql_fetch_array($invinfo2))
      {
      print "<tr><td>$invinfo3[name]</td><td>$invinfo3[stats]</td><td>$invinfo3[statadd]</td><td>$invinfo3[type]</td><td><A href='battle.php?randid=$invinfo3[randid]&creature=$creature'>Use Item</td></tr>";
       $counter = 1;

      }

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

      if ($counter == 0)
      {
            echo "<center>You have Nothing in your inventory!<br>";
            echo "<a href='battle.php?creature=$creature'>Go Back</center>";
            exit;
      }

    echo "<center><a href='battle.php?creature=$creature'>NeverMind</center>";
    
    ?>
Post Reply

Return to “Older Browser MMO Videos”