Just make the image link to your battle page and add a url variable that states which creature
Code: Select all
<a href="battle.php?creature=goblin"><img scr="goblin_pic.png"></a>
then query the creatures table by creature name
Code: Select all
<a href="battle.php?creature=goblin"><img scr="goblin_pic.png"></a>
Code: Select all
Levelup2.php
<?php
include_once 'phpinclude/connect.php';
session_start();
?>
<!--logo -->
<?php
include_once 'phpinclude/logo.php';
?>
<?php
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
}
else
{
include_once ('phpinclude/indexloginfalse.php');
}
include_once ('phpinclude/logoutbutton.php');
?>
<?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 ('phpinclude/statpanel.php');
include_once ('phpinclude/deathcheck.php');
$playerid = $playerinfo3['id'];
?>
<div id="table">
<?php
$expneeded = ($playerinfo3['level'] * 100) * $playerinfo3['level'];
if ($playerinfo3['exper'] >= $expneeded)
{
$stat = $_GET['stat'];
switch($stat)
{
case 'att';
$statname = 'attack';
$mod = 1;
break;
case 'def';
$statname = 'defense';
$mod = 1;
break;
case 'hp';
$statname = 'maxhp';
$mod = 5;
break;
case 'sp';
$statname = 'maxsp';
$mod = 5;
break;
}
$updateplayer="update players set `$statname`=`$statname`+'$mod',level=level+1 where id='$playerid'";
mysql_query=($updateplayer) or die("Could not update player"); //////////////This is line 87
echo "You are now level " . $playerinfo3['level'] . "! <br><br><a href='index.php'>Return to town</a>";
}
else
{
echo "You do not have enough experience to level up right now! <br><br> <a href='index.php'>Go back</a>";
}
?>
</div>
Code: Select all
switch($stat)
{
case 'att':
$statname = 'attack';
$mod = 1;
break;
case 'def':
$statname = 'defense';
$mod = 1;
break;
case 'hp':
$statname = 'maxhp';
$mod = 5;
break;
case 'sp':
$statname = 'maxsp';
$mod = 5;
break;
}
Code: Select all
$updateplayer="update players set `$statname`=`$statname`+'$mod',level=level+1 where id='$playerid'";
Ahhh, so kind of like a basic pointer, then. I didn't know you could do that.hallsofvallhalla wrote:backticks sometimes are needed to tell PHP to use the actual variable and not the variable name. usually though its only needed when naming the table name. This way if $statname = strength, it won't add strength + 12 but will add the variable assigned to strength to 12.
Code: Select all
mysql_query=($updateplayer) or die("Could not update player");
Code: Select all
$query = "your query string here";
$qResults = mysqli_query($db, $query);
$qArray = mysqli_fetch_array($qResults);
Code: Select all
$query = "update players set `$statname`=`$statname`+'$mod',level=level+1 where id='$playerid'";
$qResults = mysqli_query($db/*db*/, $query);
$qArray = mysqli_fetch_array($qResults);