Page 1 of 1

Battle.php (could not get player stats!)

Posted: Mon Oct 15, 2012 7:44 pm
by m1steha
If i go to /....battle.php it just shows me

could not get player stats!
Battle.php code is

Code: Select all

<?php
include 'connect.php';




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

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

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 where fighting");
$creatureinfo3=mysql_fetch_array($creatureinfo2);

}
else
{
$creatureinfo="SELECT * from creatures order by rand() limit 1";
$creatureinfo2=mysql_query($creatureinfo) or die("colud get a creature!");
$creatureifo3=mysql_fetch_array($creatureinfo2) ;
}

$creature= $creatureinfo3['name'];
$creaturehp = $creatureinfo3['hpoints'];
$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>";

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

?>

Re: Battle.php (could not get player stats!)

Posted: Tue Oct 16, 2012 1:55 am
by Jackolantern
Have you verified every part of that query with your database? Have you tried running the query through phpMyAdmin? We have it pretty well narrowed down since the message you are getting is the die() message from the first couple lines of code, I believe (unless you have the same die() message used multiple times, which is not a good idea).

Re: Battle.php (could not get player stats!)

Posted: Tue Oct 16, 2012 2:28 am
by ronislegend
Is your players name 'player1', or should there be a variable $player1 ?

Re: Battle.php (could not get player stats!)

Posted: Tue Oct 16, 2012 3:46 am
by Jackolantern
I am assuming the 'player1' is just a test he made while debugging his script since he is not setting up any variables. However, if that is supposed to be a variable, then I think you have probably found your issue :)

Re: Battle.php (could not get player stats!)

Posted: Tue Oct 16, 2012 3:42 pm
by m1steha
Not working!! any other ideas ??

Re: Battle.php (could not get player stats!)

Posted: Wed Oct 17, 2012 5:09 pm
by hallsofvallhalla
change

Code: Select all

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

Code: Select all

$playerinfo="SELECT * from players where name='player1'";
$playerinfo2=mysql_query($playerinfo)or die (mysql_error());
$playerinfo3=mysql_fetch_array($playerinfo2);
then see what it says