Page 1 of 1

What's wrong with..

Posted: Wed Mar 09, 2011 8:57 pm
by Huezzer
Hey I'm just wondering what's wrong with this code:
I want it to get you to a different location. Deep lake if you are Level 20 and Dark Cave if you are 40. And if you aren't the requiered level it will say: "You are not high level enough for this location", And it will send you back to the previous location. Also when you travel to a location it will
cost ''X'' gold. And if you haven't got the money, "You don't have enough gold for this trip" Or something like that. but can't figure out how to do it, just getting errors etc., Hope you know what I mean. (by the way: It says errror: Line 52, 53, 54 (marked) and it warns for error with $location.

Thanks!

Code: Select all

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

include 'logo.php';
?>
 <link href="style.css" rel="stylesheet" type="text/css" />
<div id="location">


<?php
if (isset($_SESSION['player']))
{
  $player=$_SESSION['player'];
}
else
{
  echo "Not Logged in <br><br> <A href='loginpage.php'>Click here for Loginpage!</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';
 ?>
 <div id ="locations">
 <?php
$playerhp = $playerinfo3['stamina'];
if ($playerhp < 1)
{
  echo "You are dead!" ;
  echo "<br><a href='useitem.php>Use an Item";
  exit;
}

if (isset($_GET['map']))
{
$bypass=1;

echo "<a href='index.php?mapchange=1&mapname=Forbidden Forest'>Forbidden Forest<br>";
echo "<br><a href='index.php?mapchange=1&mapname=Deep Lake'>Deep Lake<br>";
echo "<br><a href='index.php?mapchange=1&mapname=The Dark Cave'>The Dark Cave<br>";
}

if(isset($_GET['mapchange']))
{
$bypass=1;
$mapname = $_GET['mapname'];
$name = $locations['name'];  <-----------Line 52,53 etc.
$level = $locations['level'];
$price = $locations['price'];
$gold = $price['gold'];

$updateplayer="update players set location='$mapname' where name='$playerinfo3[name]'";
  mysql_query($updateplayer) or die("Could not update player");

$updateplayer="update players set gold='$gold' where name='$player'";
{
 echo "You do not have enough gold for this trip!";
   echo "<center><a href='index.php'>Go Back</center>";
  exit;

if ($playerinfo3['level'] > $location['level'])
{
echo "You are not high level enough to get to this Area!";
echo "<center><a href='index.php'>Go Back</center>";
exit;

  if (playerinfo3['gold'] = location['price'])
{
echo "You have traveled to " . $mapname . ".<br>";
echo "<a href='index.php'>To location</a><br>";
exit;
}

if($bypass = 1)
{
echo "<br><b><big><u>" . $playerinfo3['location'] . "</u></big><br>";
echo "<br><b><big><u>Locations</u></big></b>";
echo "<br><a href='store.php'>Visit Store<br>";
echo "<a href='inn.php'>Visit Innkeeper<br>";
echo "<a href='spelltrainer.php'>Visit Spell trainer<br>";
echo "<a href='useitem.php'>Use Items<br>";
echo "<a href='armorshop.php'>Visit Armorshop!<br>";
echo "<a href='weaponshop.php'>Visit Weaponshop<br>";
echo "<a href='battle.php'>Battle in Arena<br>";
echo "<a href='game.php?map=1'>Go to Map</a><br>";
}
}
?>
</div>
<div id="logout">
<?php
echo "<br><a href='logout.php'><img src='images/logout.gif'>";
?>
</div>

Re: What's worng with..

Posted: Fri Mar 11, 2011 4:23 pm
by Huezzer
Anyone?

Re: What's worng with..

Posted: Sat Mar 12, 2011 8:55 pm
by Chris
Hi, im in the coffee shop rather stoned and on my phone so it's difficult to copie and paste yor code, but because you asked, I think on what I'm guessing is line 56, your sql query says "set location : '$mapname' or something, but I'm guessing the variable shoulx be $name

Re: What's worng with..

Posted: Mon Mar 14, 2011 7:27 pm
by hallsofvallhalla
you dont have a query for $locations['name']...

Re: What's wrong with..

Posted: Mon Mar 14, 2011 7:42 pm
by Huezzer
Thank you halls!, I'll make a new code for it and I'll post it here. And you will see if I made it :P

Huezzer. :)

Re: What's wrong with..

Posted: Mon Mar 14, 2011 8:33 pm
by Huezzer
Hey, I think this is totaly wrong because I get an error:

**Parse error: syntax error, unexpected '[' in C:\wamp\www\tutorial\index.php on line 56

Index.php

Code: Select all

<?php
include_once 'connect.php';
session_start();
include 'logo.php';
?>
<link href="style.css" rel="stylesheet" type="text/css" />
<title>ZonThiz</title>
<div id="login">
<div id="login2">


<?php
if (isset($_SESSION['player']))
{
  $player=$_SESSION['player'];
}
else
{
echo "<center><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>Not Logged in <br><br> <A href='login.php'>Login</a></center>";
  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';
 ?>
<div id ="locations">
<?php
$bypass= 0;
$playersm = $playerinfo3['stamina'];
if ($playersm < 1)
{
  echo "You are dead!" ;
  echo "<br><a href='useitem.php>Use an Item";
  exit;
}

if (isset($_GET['map']))
{
$bypass=1;
echo "<a href='index.php?mapchange=1&mapname=Forbidden Forest'>Forbidden Forest";
echo "<br><a href='index.php?mapchange=1&mapname=Savannah'>The Savannah";
echo "<br><a href='index.php?mapchange=1&mapname=Deep Lake'>Deep Lake";
echo "<br><a href='index.php?mapchange=1&mapname=The Dark Cave'>The Dark Cave";
}

if(isset($_GET['mapchange']))
{
$bypass=1;
$mapname = $_GET['mapname'];
$name = $location['name'];
$location = $location['level'];
$level = playerinfo3['level'];
$price = $location['price'];
$gold = $price['gold'];

$query = "SELECT location,name from locations where name='$locations' AND name='$name'";
  $location = mysql_query($query) or die("Could not query locations");
  $location2 = mysql_fetch_array($location);
  
$updateplayer="update players set location='$mapname' where name='$playerinfo3[name]'";
  mysql_query($updateplayer) or die("Could not update player");

$updateplayer="update players set gold='$gold' where name='$player'";
{
echo "You do not have enough gold for this trip!";
   echo "<center><a href='index.php'>Go Back</center>";
  exit;

if ($playerinfo3['level'] > $location['level'])
{
echo "You are not high level enough to get to this Area!";
echo "<center><a href='index.php'>Go Back</center>";
exit;
}
if (playerinfo3['gold'] = location['price'])
{
echo "You have traveled to " . $mapname . ".<br>";
echo "<a href='index.php'>To location</a><br>";
exit;
}

if($bypass = 1)
{
echo "<br><b><big><u>" . $playerinfo3['location'] . "</u></big><br>";
echo "<br><b><big><u>Locations</u></big></b>";
echo "<br><a href='store.php'>Visit Store<br>";
echo "<a href='inn.php'>Visit Innkeeper<br>";
echo "<a href='spelltrainer.php'>Visit Spell trainer<br>";
echo "<a href='useitem.php'>Use Items<br>";
echo "<a href='armorshop.php'>Visit Armorshop!<br>";
echo "<a href='weaponshop.php'>Visit Weaponshop<br>";
echo "<a href='battle.php'>Battle in Arena<br>";
echo "<a href='game.php?map=1'>Go to Map</a><br>";
}
}
?>
</div>
<div id="logout">
<?php
echo "<br><a href='logout.php'><img src='images/logout.gif'>";
?>
</div>
And I think This part is wrong, Am I right?:

Code: Select all

$mapname = $_GET['mapname'];
$name = $location['name'];
$location = $location['level'];
$level = playerinfo3['level'];
$price = $location['price'];
$gold = $price['gold'];

$query = "SELECT location,name from locations where name='$locations' AND name='$name'";
  $location = mysql_query($query) or die("Could not query locations");
  $location2 = mysql_fetch_array($location);

Re: What's wrong with..

Posted: Tue Mar 15, 2011 12:41 am
by 62896dude
Sorry, I couldn't quite figure out what is wrong :/ but i was skimming through your code, and funny enough, I am making a harry potter game right now also! :)

Re: What's wrong with..

Posted: Tue Mar 15, 2011 6:48 am
by PaxBritannia
$level = playerinfo3['level'];
playerinfo3 needs '$' before it. So it becomes:
$level = $playerinfo3['level'];
You've also left it out at line 79 as well. Just use Ctrl+F and search for "playerinfo" until you find the ones missing it. :)

pax.

Re: What's wrong with..

Posted: Tue Mar 15, 2011 10:15 pm
by 62896dude
Nice catch Pax! :)

Re: What's wrong with..

Posted: Fri Mar 18, 2011 8:51 pm
by hallsofvallhalla
so whats all wrong now?