Help Please (unexpected T_ELSE, expecting T_FUNCTION)

C++, C#, Java, PHP, ect...
Post Reply
Neokai
Posts: 4
Joined: Sat Jun 25, 2011 8:59 am

Help Please (unexpected T_ELSE, expecting T_FUNCTION)

Post by Neokai »

Lol, for some reason I tried to put it in, but it doesn't work! So, I'm just re-posting the original coding source before the changes I made. Yes, I'm still a Noob Saibot who learns quick. :P Help would be GREATLY appreciated, also sorry if the code seems sloppy! xD

Here's the following error:
Parse error: syntax error, unexpected T_ELSE, expecting T_FUNCTION in ********************************************* on line 33

Script:

Code: Select all

<?php

require_once ("data_class.php");class Creature extends Data 
{	function Init() {	$this->GetUserData();}	
function NextLevel()
{$qc = mysql_query("SELECT hp FROM creatures_data WHERE id = '".$this->creature[creature_id]."'"); $this->base = mysql_fetch_assoc($qc); $this->expNeeded = ceil(($this->base[hp] *  ($this->creature[level] * $this->creature[level])) * (1.79 + ($this->creature[level] / 10)));	
if ($this->creature[exp] >= $this->expNeeded) {	$u = mysql_query("UPDATE player_creatures SET level = level + 1, skillpoints = skillpoints + 3 WHERE user_id = '".$_SESSION["id"]."'");		
$this->Init();						if ($this->creature[skillpoints] > 0) {$this->exp = $this->expNeeded . " (<a href='?o=level'><b><font color='red'><blink>+up</blink></font></b></a>)";}			
else {		$this->exp = $this->expNeeded;	}} 
else {		if ($this->creature[skillpoints] > 0) {			$this->exp = $this->expNeeded . " (<a href='?o=level'><b><font color='red'><blink>+up</blink></font></b></a>)";	}		
else {		$this->exp = $this->expNeeded;		}}}	function CreatureDetails () {$this->Init();//treba iskalkulirati slijedeci level za XP, pa pozivamo funkciju koja to radi :)$this->NextLevel();								
echo "<table align='left' width='280' border='0'><tr>"; 				
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;' colspan='2'><b>".$this->creature[name]."</b> (<a href='?o=cudoviste'><i>Edit</i></a>)</td></tr><tr>";		
echo "<td>Class:</td>";		echo "<td>".$this->creature[type]."</td></tr><tr>";		
echo "<td>HP:</td>";		echo "<td>".$this->creature[hp]."</td></tr><tr>";		
echo "<td>Speed:</td>";		
echo "<td>".$this->creature[speed]."</td></tr><tr>";				
echo "<td>ATT:</td>";		
echo "<td>".$this->creature[att]."</td></tr><tr>";		
echo "<td>DEF:</td>";		
echo "<td>".$this->creature[def]."</td></tr><tr>";				
echo "<td>Level:</td>";		echo "<td>".$this->creature[level]."</td></tr><tr>";		
echo "<td>XP:</td>";		echo "<td>".$this->creature[exp]."/".$this->exp."</td></tr><tr>";			
echo "<td>Gold:</td>";		echo "<td>".$this->creature[gold]." coins</td></tr><tr>";			
echo "<td colspan='2' style='margin-bottom: 2px; border-bottom: 1px solid #ccc; border-top: 1px solid #ccc;'>Activities...</td></tr><tr>";			
echo "<td colspan='2'><b>Currently:</b></td></tr><tr>";		
echo "<td colspan='2'>".$this->creature[current_action]."</td>";				
echo "</tr></table>";}			

function ShowSkills() {	$this->Init();	$i = 1;	 while ($i <= $this->max) {				
echo "<tr><td>". $this->skill[$i][name] ." <a href='' title='header=[Skill info] body=[".$this->skill[$i][name]."<br />".$this->skill[$i][effect]."]'>[?]</a></td></tr>";
$i++;}} //function CreatureSkills() {$this->Init(); "<table width='280' align='right' border='0'>"; "<tr><td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Creature info: </td></tr>"; "<tr><td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>".$this->creature[description]."</td></tr>"; "<tr><td>Total skills: $this->max</td></tr>"; "<tr><td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Latest skills: (<a href='?o=skills'><b><i>View all</i></b></a>)</td></tr>"; $s = mysql_query("SELECT * FROM skills WHERE creature_id = '".$this->creature[id]."' AND level <= '".$this->creature[level]."' ORDER BY id DESC LIMIT 5");		$this->max = mysql_num_rows($s); if ($this->max > 0) {	$i = 1;	while ($i <= $this->max) {$this->skill[$i] = mysql_fetch_assoc($s);$i++;} $this->ShowSkills();}
else {						echo "<tr><td>This creature has no special skills yet.</td></tr>";						}		echo "</tr></table>";	} //			function EditCreature() {				$this->Init();
if (isset($_POST["scname"]) && $_POST["scname"] == 'Change name' && !empty($_POST["cname"])) {	$cname = mysql_real_escape_string($_POST["cname"]);			$u = mysql_query("UPDATE player_creatures SET name = '$cname' WHERE user_id = '".$_SESSION['id']."'");					$value = $cname;		} 
else {$value = $this->creature[name]; $msg = $this->creature[current_action];}								
echo "<form action='?o=cudoviste' method='post'";		
echo "<table width='280' align='left' border='10'><tr>";		
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Creature details: </td></tr><tr>";		echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Creature name: <input type='text' name='cname' value='$value'/></td></tr><tr>";      
//echo "<td>Custom 'current action' message:<br /><input type='text' name='cmsg' value='$msg'/ style='width: 250px;'></td></tr><tr>";		
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'><input type='submit' value='Change details' name='scname' /></td>";		
echo "</tr></table>";		
echo "</form>";	} function LevelUp ($attribute) {								
if ($this->creature[skillpoints] > 0) {			if ($attribute == 'speed') {	$u = mysql_query("UPDATE player_creatures SET $attribute = $attribute + 0.2, skillpoints = skillpoints - 1 WHERE user_id = '".$_SESSION['id']."'");		} 
else {	$u = mysql_query("UPDATE player_creatures SET $attribute = $attribute + 1, skillpoints = skillpoints - 1 WHERE user_id = '".$_SESSION['id']."'");}} 
else {						
echo "<tr><td colspan='2'><b><blink>You have no skillpoints to distribute!</blink></b></td></tr>";	}} function SkillsDetail () {$this->Init()$s = mysql_query("SELECT * FROM skills WHERE creature_id = '".$this->creature[id]."' AND level <= '".$this->creature[level]."' ORDER BY id DESC LIMIT 5");	$this->max = mysql_num_rows($s); 
if ($this->max > 0) {$i = 1;	while ($i <= $this->max) {	$this->skill[$i] = mysql_fetch_assoc($s);$i++;}}		
else {						
echo "<table align='center' width='300'  border='0'><tr>";
echo "<td>This creature has<br />no special skills yet.</td>";			
echo "</tr></table>";			}			
echo "<table width='280' align='left' border='0'><tr>";		
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Creature info: </td></tr><tr>";		
echo "<td>Total skills: $this->max</td></tr><tr>";echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>All skills:</td></tr><tr>";				$i = 1;		while ($i <= $this->max) {				
echo "<td>". $this->skill[$i][name] ." <a href='' title='header=[Skill info] body=[".$this->skill[$i][name]."<br />".$this->skill[$i][effect]."]'>[?]</a></td></tr><tr>";				$i++;		}				
echo "</tr></table>";					}		function LevelInfo() {				echo "<table width='280' align='left' border='0'><tr>";				if (isset($_GET["u"]) && $_GET["u"] == 'att' && $_GET["o"] == 'level') {			$a = 'att';			$this->LevelUp($a);
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Attack + 1</td></tr><tr>";		}
else if (isset($_GET["u"]) && $_GET["u"] == 'def' && $_GET["o"] == 'level') {			$a = 'def';		    $this->LevelUp($a);				
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Defence + 1</td></tr><tr>";		}		else if (isset($_GET["u"]) && $_GET["u"] == 'sp' && $_GET["o"] == 'level') {			$a = 'speed';			$this->LevelUp($a);
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Speed + 0,2</td></tr><tr>";		}
else {		
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Level up</td></tr><tr>";	}	$this->Init();	$this->points = $this->creature[skillpoints];				if ($this->points <= 0) {			$la = "(<i>+</i>)";			$ld = "(<i>+</i>)";			$ls = "(<i>+</i>)";		} 
else {			$la = "(<a href='?o=level&u=att'><b>+</b></a>)";			$ld = "(<a href='?o=level&u=def'><b>+</b></a>)";			$ls = "(<a href='?o=level&u=sp'><b>+</b></a>)";			}
echo "<td>Total exp: ". $this->creature[exp] ."</td></tr><tr>";		
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Total points: ". $this->points ."</td></tr><tr>";	
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Creature attributes:</td></tr><tr>";				
echo "<td>Attack: ". $this->creature[att] ." $la</td></tr><tr>";		
echo "<td>Defence: ". $this->creature[def] ." $ld</td></tr><tr>";		echo "<td>Speed: ". $this->creature[speed] ." $ls<br /><br />		*Note: with one point you can increase speed only by 0.2</td></tr><tr>";				
echo "</tr></table>";		} // function			function DrawGUI() {	$this->CreatureDetails(); $this->CreatureSkills();			}	} // end class
?>
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Help Please (unexpected T_ELSE, expecting T_FUNCTION)

Post by Jackolantern »

I don't even know where to begin... lol

Has this been put through some kind of code obfuscation or was the whitespacing broken when pasted into the browser? There are entire lines that are inside quotation marks seemingly for no reason. Komodo picked up that there is an error on line 33, but it seems to be an error on line 32. Maybe missing an ECHO that would account for the quoted code lines on 32?

I can't make heads or tails of this code, and there is no way you will be able to in a month or so either. Your code desperately needs to be cleaned up and commented, or this project is asking to crash and burn as it grows more complex. It needs each line to be on a real, separate line, it needs comments, it needs coherent whitespacing, etc.
The indelible lord of tl;dr
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Help Please (unexpected T_ELSE, expecting T_FUNCTION)

Post by SpiritWebb »

I got a headache skimming through looking at it...I didn't know where to start... O.o
Image

Image
User avatar
Zak Zillion
Posts: 112
Joined: Thu Apr 07, 2011 12:55 am

Re: Help Please (unexpected T_ELSE, expecting T_FUNCTION)

Post by Zak Zillion »

fixed

You had a lot of stuff commented out because you put // which comments out the entire line, that would be ok except you didn't start a new line after you commented it out.

Code: Select all

<?php
require_once("data_class.php");
class Creature extends Data
    {
    function Init()
        {
        $this->GetUserData();
        }
    function NextLevel()
        {
        $qc              = mysql_query("SELECT hp FROM creatures_data WHERE id = '" . $this->creature[creature_id] . "'");
        $this->base      = mysql_fetch_assoc($qc);
        $this->expNeeded = ceil(($this->base[hp] * ($this->creature[level] * $this->creature[level])) * (1.79 + ($this->creature[level] / 10)));
        if ($this->creature[exp] >= $this->expNeeded)
            {
            $u = mysql_query("UPDATE player_creatures SET level = level + 1, skillpoints = skillpoints + 3 WHERE user_id = '" . $_SESSION["id"] . "'");
            $this->Init();
            if ($this->creature[skillpoints] > 0)
                {
                $this->exp = $this->expNeeded . " (<a href='?o=level'><b><font color='red'><blink>+up</blink></font></b></a>)";
                } //$this->creature[skillpoints] > 0
            else
                {
                $this->exp = $this->expNeeded;
                }
            } //$this->creature[exp] >= $this->expNeeded
        else
            {
            if ($this->creature[skillpoints] > 0)
                {
                $this->exp = $this->expNeeded . " (<a href='?o=level'><b><font color='red'><blink>+up</blink></font></b></a>)";
                } //$this->creature[skillpoints] > 0
            else
                {
                $this->exp = $this->expNeeded;
                }
            }
        }
    function CreatureDetails()
        {
        $this->Init(); //treba iskalkulirati slijedeci level za XP, pa pozivamo funkciju koja to radi :)$this->NextLevel();                        
        echo "<table align='left' width='280' border='0'><tr>";
        echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;' colspan='2'><b>" . $this->creature[name] . "</b> (<a href='?o=cudoviste'><i>Edit</i></a>)</td></tr><tr>";
        echo "<td>Class:</td>";
        echo "<td>" . $this->creature[type] . "</td></tr><tr>";
        echo "<td>HP:</td>";
        echo "<td>" . $this->creature[hp] . "</td></tr><tr>";
        echo "<td>Speed:</td>";
        echo "<td>" . $this->creature[speed] . "</td></tr><tr>";
        echo "<td>ATT:</td>";
        echo "<td>" . $this->creature[att] . "</td></tr><tr>";
        echo "<td>DEF:</td>";
        echo "<td>" . $this->creature[def] . "</td></tr><tr>";
        echo "<td>Level:</td>";
        echo "<td>" . $this->creature[level] . "</td></tr><tr>";
        echo "<td>XP:</td>";
        echo "<td>" . $this->creature[exp] . "/" . $this->exp . "</td></tr><tr>";
        echo "<td>Gold:</td>";
        echo "<td>" . $this->creature[gold] . " coins</td></tr><tr>";
        echo "<td colspan='2' style='margin-bottom: 2px; border-bottom: 1px solid #ccc; border-top: 1px solid #ccc;'>Activities...</td></tr><tr>";
        echo "<td colspan='2'><b>Currently:</b></td></tr><tr>";
        echo "<td colspan='2'>" . $this->creature[current_action] . "</td>";
        echo "</tr></table>";
        }
    function ShowSkills()
        {
        $this->Init();
        $i = 1;
        while ($i <= $this->max)
            {
            echo "<tr><td>" . $this->skill[$i][name] . " <a href='' title='header=[Skill info] body=[" . $this->skill[$i][name] . "<br />" . $this->skill[$i][effect] . "]'>[?]</a></td></tr>";
            $i++;
            } //$i <= $this->max
        }
    function CreatureSkills()
        {
        $this->Init();
        "<table width='280' align='right' border='0'>";
        "<tr><td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Creature info: </td></tr>";
        "<tr><td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>" . $this->creature[description] . "</td></tr>";
        "<tr><td>Total skills: $this->max</td></tr>";
        "<tr><td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Latest skills: (<a href='?o=skills'><b><i>View all</i></b></a>)</td></tr>";
        $s         = mysql_query("SELECT * FROM skills WHERE creature_id = '" . $this->creature[id] . "' AND level <= '" . $this->creature[level] . "' ORDER BY id DESC LIMIT 5");
        $this->max = mysql_num_rows($s);
        if ($this->max > 0)
            {
            $i = 1;
            while ($i <= $this->max)
                {
                $this->skill[$i] = mysql_fetch_assoc($s);
                $i++;
                } //$i <= $this->max
            $this->ShowSkills();
            } //$this->max > 0
        else
            {
            echo "<tr><td>This creature has no special skills yet.</td></tr>";
            }
        echo "</tr></table>";
        }
    function EditCreature()
        {
        $this->Init();
        if (isset($_POST["scname"]) && $_POST["scname"] == 'Change name' && !empty($_POST["cname"]))
            {
            $cname = mysql_real_escape_string($_POST["cname"]);
            $u     = mysql_query("UPDATE player_creatures SET name = '$cname' WHERE user_id = '" . $_SESSION['id'] . "'");
            $value = $cname;
            } //isset($_POST["scname"]) && $_POST["scname"] == 'Change name' && !empty($_POST["cname"])
        else
            {
            $value = $this->creature[name];
            $msg   = $this->creature[current_action];
            }
        echo "<form action='?o=cudoviste' method='post'";
        echo "<table width='280' align='left' border='10'><tr>";
        echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Creature details: </td></tr><tr>";
        echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Creature name: <input type='text' name='cname' value='$value'/></td></tr><tr>";
        //echo "<td>Custom 'current action' message:<br /><input type='text' name='cmsg' value='$msg'/ style='width: 250px;'></td></tr><tr>";      
        echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'><input type='submit' value='Change details' name='scname' /></td>";
        echo "</tr></table>";
        echo "</form>";
        }
    function LevelUp($attribute)
        {
        if ($this->creature[skillpoints] > 0)
            {
            if ($attribute == 'speed')
                {
                $u = mysql_query("UPDATE player_creatures SET $attribute = $attribute + 0.2, skillpoints = skillpoints - 1 WHERE user_id = '" . $_SESSION['id'] . "'");
                } //$attribute == 'speed'
            else
                {
                $u = mysql_query("UPDATE player_creatures SET $attribute = $attribute + 1, skillpoints = skillpoints - 1 WHERE user_id = '" . $_SESSION['id'] . "'");
                }
            } //$this->creature[skillpoints] > 0
        else
            {
            echo "<tr><td colspan='2'><b><blink>You have no skillpoints to distribute!</blink></b></td></tr>";
            }
        }
    function SkillsDetail()
        {
        $this->Init();
        $s         = mysql_query("SELECT * FROM skills WHERE creature_id = '" . $this->creature[id] . "' AND level <= '" . $this->creature[level] . "' ORDER BY id DESC LIMIT 5");
        $this->max = mysql_num_rows($s);
        if ($this->max > 0)
            {
            $i = 1;
            while ($i <= $this->max)
                {
                $this->skill[$i] = mysql_fetch_assoc($s);
                $i++;
                } //$i <= $this->max
            } //$this->max > 0
        else
            {
            echo "<table align='center' width='300'  border='0'><tr>";
            echo "<td>This creature has<br />no special skills yet.</td>";
            echo "</tr></table>";
            }
        echo "<table width='280' align='left' border='0'><tr>";
        echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Creature info: </td></tr><tr>";
        echo "<td>Total skills: $this->max</td></tr><tr>";
        echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>All skills:</td></tr><tr>";
        $i = 1;
        while ($i <= $this->max)
            {
            echo "<td>" . $this->skill[$i][name] . " <a href='' title='header=[Skill info] body=[" . $this->skill[$i][name] . "<br />" . $this->skill[$i][effect] . "]'>[?]</a></td></tr><tr>";
            $i++;
            } //$i <= $this->max
        echo "</tr></table>";
        }
    function LevelInfo()
        {
        echo "<table width='280' align='left' border='0'><tr>";
        if (isset($_GET["u"]) && $_GET["u"] == 'att' && $_GET["o"] == 'level')
            {
            $a = 'att';
            $this->LevelUp($a);
            echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Attack + 1</td></tr><tr>";
            } //isset($_GET["u"]) && $_GET["u"] == 'att' && $_GET["o"] == 'level'
        else if (isset($_GET["u"]) && $_GET["u"] == 'def' && $_GET["o"] == 'level')
            {
            $a = 'def';
            $this->LevelUp($a);
            echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Defence + 1</td></tr><tr>";
            } //isset($_GET["u"]) && $_GET["u"] == 'def' && $_GET["o"] == 'level'
        else if (isset($_GET["u"]) && $_GET["u"] == 'sp' && $_GET["o"] == 'level')
            {
            $a = 'speed';
            $this->LevelUp($a);
            echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Speed + 0,2</td></tr><tr>";
            } //isset($_GET["u"]) && $_GET["u"] == 'sp' && $_GET["o"] == 'level'
        else
            {
            echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Level up</td></tr><tr>";
            }
        $this->Init();
        $this->points = $this->creature[skillpoints];
        if ($this->points <= 0)
            {
            $la = "(<i>+</i>)";
            $ld = "(<i>+</i>)";
            $ls = "(<i>+</i>)";
            } //$this->points <= 0
        else
            {
            $la = "(<a href='?o=level&u=att'><b>+</b></a>)";
            $ld = "(<a href='?o=level&u=def'><b>+</b></a>)";
            $ls = "(<a href='?o=level&u=sp'><b>+</b></a>)";
            }
        echo "<td>Total exp: " . $this->creature[exp] . "</td></tr><tr>";
        echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Total points: " . $this->points . "</td></tr><tr>";
        echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Creature attributes:</td></tr><tr>";
        echo "<td>Attack: " . $this->creature[att] . " $la</td></tr><tr>";
        echo "<td>Defence: " . $this->creature[def] . " $ld</td></tr><tr>";
        echo "<td>Speed: " . $this->creature[speed] . " $ls<br /><br />      *Note: with one point you can increase speed only by 0.2</td></tr><tr>";
        echo "</tr></table>";
        } // function        
    function DrawGUI()
        {
        $this->CreatureDetails();
        $this->CreatureSkills();
        }
    } // end class
?>
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - Albert Einstein

Old Project(s):
The Dark Flame
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: Help Please (unexpected T_ELSE, expecting T_FUNCTION)

Post by Xaleph »

I like the fact you actually sanitized it! However, what I don`t like is the fact the original author is using objects ( logic, data) as view files. Seems someone missed a lesson on MVC ;)
Post Reply

Return to “Coding”