Page 1 of 1

php trouble

Posted: Thu Sep 10, 2009 8:01 pm
by RustyDoorknobs
I keep getting this error:

Parse error: syntax error, unexpected T_VARIABLE in /home/myavatar/public_html/cardtest2.php on line 18

Heres my code:

Code: Select all

<?php
 
 
 
//Script (c) 2009 http://www.gamebattleshq.com
 
 
//include into teamcards
 
//v1.0
 
 
//
 
 
//Load in DOM Doc
$u = $_GET["u"]
$stats = new DOMDocument();
$stats_xml = $u . "/stats.xml";
$stats->load( $stats_xml );
 
//
 
//Assign tags to vars:
 
$n = "name";
$xp = "xp";
$w = "wins";
$l = "losses";
$s = "streak";
$p = "place";
$wp = "winPercentage";
$mp = "matchesPlayed";
$r = "reputation";
$lv = "level";
 
//
 
//Variable loading function:
function get($tag);
{
$i= $stats->getElementsByTagName($tag);
$s = $i->item(0)->nodeValue;
echo $s
}
 
 
//Format for entering a stat:
//USE:    * <span id="STATNAME"><?php get($stat) ?></span> *
 
//
 
//End of Script.
//Script by Alex Kizer.
 
get("$n");
 
?>

Re: php trouble

Posted: Thu Sep 10, 2009 8:12 pm
by SimonMayer
The problem is on line 17
There should be a semi-colon ; at the end of the line, like so:

Code: Select all

$u = $_GET["u"];
the semi-colon stops the PHP code being read as one statement. The problem only becomes apparent when it reads line 18, as "$u = $_GET["u"] $stats = new DOMDocument();" does not make sense.

Re: php trouble

Posted: Fri Sep 11, 2009 7:01 am
by RustyDoorknobs
I fixed up some stuff but i still get this:

Fatal error: Call to a member function getElementsByTagName() on a non-object in /home/myavatar/public_html/cardtest2.php on line 42

I understand it's in my function, so heres my code:

Code: Select all

<?php
 
 
 
//Script (c) 2009 http://www.gamebattleshq.com
 
 
//include into teamcards
 
//v1.0
 
 
//
 
 
//Load in DOM Doc
$u = $_GET["u"];
$stats = new DOMDocument();
$stats_xml = $u . "/stats.xml";
$stats->load( $stats_xml );
 
//
 
//Assign tags to vars:
 
$n = "name";
$xp = "xp";
$w = "wins";
$l = "losses";
$s = "streak";
$p = "place";
$wp = "winPercentage";
$mp = "matchesPlayed";
$r = "reputation";
$lv = "level";
 
//
 
//Variable loading function:
function get($tag)
{
$i= $stats->getElementsByTagName($tag);
$s = $i->item(0)->nodeValue;
echo $s;
}
 
 
 
get("$n");
 
?>

Re: php trouble

Posted: Fri Sep 11, 2009 7:15 am
by jackpf
$stats is not in the function's scope.

Re: php trouble

Posted: Fri Sep 11, 2009 2:59 pm
by RustyDoorknobs
Thanks ya ol goose!

Re: php trouble

Posted: Fri Sep 11, 2009 3:22 pm
by jackpf
;)