Page 1 of 1
Battle Problem [Resolved]
Posted: Thu Aug 22, 2013 9:32 am
by Epiales
Okay, last post for the night. Got to rest sometime
I've looked over and over. I've tried redoing, but always come up with the same result.
Code: Select all
Parse error: syntax error, unexpected 'else' (T_ELSE)
It's the last else in the battle.php! I have to have that there, so I don't know why I can't fix it. Probably b/c I've been up for 20 hours coding LOL. Anyway, if anyone can notice what's wrong, that's great. If not, no worries. I'll be up later to check it out again. Thanks for the help all. At one time I had it working, but it kept saying I visited the page wrong, which shouldn't of said that, but I messed it up somehow. Probably something small. Night everyone!
Code: Select all
<?php
session_start();
include("header.php");
if(!isset($_SESSION['uid'])){
echo "You must be logged in to view this page!";
}else
if (isset($_GET['characters']))
{
$characters=$_GET['characters'];
$charactersinfo = "SELECT * from characters where name = '$characters'";
$charactersinfo2 = mysql_query($charactersinfo) or die ("Could not get the character you were fighting!");
$charactersinfo3 = mysql_fetch_array($charactersinfo2);
} else {
$charactersinfo = "SELECT * from characters order by rand() limit 1";
$charactersinfo2 = mysql_query($charactersinfo) or die ("Could not get a character!");
$charactersinfo3 = mysql_fetch_array($charactersinfo2);
$characters = $charactersinfo3['name'];
$charactershp = $charactersinfo3['hpoints'];
$charactersattack = $charactersinfo3['attack'];
$charactersdefense = $charactersinfo3['defense'];
echo "<u> " . $user['username'] . "</u>";
echo "<br>";
echo "Hit Points = " . $stats['hpoints'] . "<br>";
echo "Attack = " . $stats['attack'] . "<br>";
echo "Defense = " . $stats['defense'] . "<br>";
echo "<br><br>";
echo "<u> " . $charactersinfo3['name'] . "</u><br>";
echo "Hit Points = " . $charactershp . "<br>";
echo "Attack = " . $charactersattack . "<br>";
echo "Defense = " . $charactersdefense . "<br>";
echo "<br>";
echo "<a href='attack.php?characters=$characters'>Attack!";
}
else{
output("You have visited this page incorrectly!");
}
}
include("footer.php");
?>
Re: Battle Problem
Posted: Thu Aug 22, 2013 9:35 am
by Jackolantern
You can only have 1 ELSE clause for each IF statement. It doesn't
have to be there because it makes no sense
Else what? You have to create an IF statement for it to be an ELSE against or the idea of the ELSE makes no sense
To fix it, you need to think of the reason why someone would get the message "You have visited this page incorrectly" and put it into an IF statement to reflect that condition.
Re: Battle Problem
Posted: Fri Aug 23, 2013 12:14 am
by Epiales
*EDITED*
I have it fixed. Wasn't thinking straight

Thx
Re: Battle Problem
Posted: Fri Aug 23, 2013 12:22 am
by Xaos
Code: Select all
<?php
session_start();
include("header.php");
if(!isset($_SESSION['uid'])){
echo "You must be logged in to view this page!";
}else //missing the { here.
if (isset($_GET['characters']))
{
$characters=$_GET['characters'];
$charactersinfo = "SELECT * from characters where name = '$characters'";
$charactersinfo2 = mysql_query($charactersinfo) or die ("Could not get the character you were fighting!");
$charactersinfo3 = mysql_fetch_array($charactersinfo2);
} else {
$charactersinfo = "SELECT * from characters order by rand() limit 1";
$charactersinfo2 = mysql_query($charactersinfo) or die ("Could not get a character!");
$charactersinfo3 = mysql_fetch_array($charactersinfo2);
$characters = $charactersinfo3['name'];
$charactershp = $charactersinfo3['hpoints'];
$charactersattack = $charactersinfo3['attack'];
$charactersdefense = $charactersinfo3['defense'];
echo "<u> " . $user['username'] . "</u>";
echo "<br>";
echo "Hit Points = " . $stats['hpoints'] . "<br>";
echo "Attack = " . $stats['attack'] . "<br>";
echo "Defense = " . $stats['defense'] . "<br>";
echo "<br><br>";
echo "<u> " . $charactersinfo3['name'] . "</u><br>";
echo "Hit Points = " . $charactershp . "<br>";
echo "Attack = " . $charactersattack . "<br>";
echo "Defense = " . $charactersdefense . "<br>";
echo "<br>";
echo "<a href='attack.php?characters=$characters'>Attack!";
}
//running double else here. You're saying }else{else}. I don't see where the "if" part of this is. What is this the else of?
else{
output("You have visited this page incorrectly!");
}
}
include("footer.php");
?>
Added comments in a few places that are error spots. Also, if you type
Code: Select all
[/ code], it makes it show in PHP ! :D
Re: Battle Problem
Posted: Fri Aug 23, 2013 12:27 am
by Epiales
Code: Select all
Notice: Undefined variable: stat in C:\xampp\htdocs\game\attack.php on line 22
Notice: Undefined variable: stat in C:\xampp\htdocs\game\attack.php on line 23
Notice: Undefined variable: stat in C:\xampp\htdocs\game\attack.php on line 24
Code: Select all
<?php
session_start();
include("header.php");
if(!isset($_SESSION['uid'])){
echo "You must be logged in to view this page!";
}else{
if (isset($_GET['characters']))
{
$characters=$_GET['characters'];
$charactersinfo = "SELECT * from characters where name = '$characters'";
$charactersinfo2 = mysql_query($charactersinfo) or die ("Could not get the character you were fighting!");
$charactersinfo3 = mysql_fetch_array($charactersinfo2);
} else {
echo "<a href='battle1.php>No Character selected. Go Back!";
exit;
}
$playershp = $stat['hpoints'];
$playersattack = $stat['attack'];
$playersdefense = $stat['defense'];
$characters = $charactersinfo3['name'];
$charactershp = $charactersinfo3['hpoints'];
$charactersattack = $charactersinfo3['attack'];
$charactersdefense = $charactersinfo3['defense'];
Errors in question:
$playershp = $stat['hpoints'];
$playersattack = $stat['attack'];
$playersdefense = $stat['defense'];
Re: Battle Problem
Posted: Fri Aug 23, 2013 12:32 am
by Xaos
Epiales wrote:Code: Select all
Notice: Undefined variable: stat in C:\xampp\htdocs\game\attack.php on line 22
Notice: Undefined variable: stat in C:\xampp\htdocs\game\attack.php on line 23
Notice: Undefined variable: stat in C:\xampp\htdocs\game\attack.php on line 24
Code: Select all
<?php
session_start();
include("header.php");
if(!isset($_SESSION['uid'])){
echo "You must be logged in to view this page!";
}else{
if (isset($_GET['characters']))
{
$characters=$_GET['characters'];
$charactersinfo = "SELECT * from characters where name = '$characters'";
$charactersinfo2 = mysql_query($charactersinfo) or die ("Could not get the character you were fighting!");
$charactersinfo3 = mysql_fetch_array($charactersinfo2);
} else {
echo "<a href='battle1.php>No Character selected. Go Back!";
exit;
}
$playershp = $stat['hpoints'];
$playersattack = $stat['attack'];
$playersdefense = $stat['defense'];
$characters = $charactersinfo3['name'];
$charactershp = $charactersinfo3['hpoints'];
$charactersattack = $charactersinfo3['attack'];
$charactersdefense = $charactersinfo3['defense'];
Errors in question:
$playershp = $stat['hpoints'];
$playersattack = $stat['attack'];
$playersdefense = $stat['defense'];
Where are you defining $stat?
Re: Battle Problem
Posted: Fri Aug 23, 2013 12:35 am
by Epiales
All of my stats are through a stat field in the database. I found it easier to do it that way. That way I can include all the links in the header.php and just call the stats from the stats field. The only thing in my users field is the username, password, and email.
Re: Battle Problem
Posted: Fri Aug 23, 2013 12:36 am
by Xaos
Epiales wrote:All of my stats are through a stat field in the database. I found it easier to do it that way. That way I can include all the links in the header.php and just call the stats from the stats field. The only thing in my users field is the username, password, and email.
Are you defining the variable in the header.php? You'd have to actually define $stat as a field in the DB
Re: Battle Problem
Posted: Fri Aug 23, 2013 12:40 am
by Epiales
OH! ((slap in face))
You asked WHERE not WHY lmao! No, I see I don't have them defined. LOL.
Re: Battle Problem
Posted: Fri Aug 23, 2013 12:41 am
by Xaos
Epiales wrote:OH! ((slap in face))
You asked WHERE not WHY lmao! No, I see I don't have them defined. LOL.
Haha. That would solve that issue. Make sure you have $stat itself defined a row in the DB.