php trouble

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
RustyDoorknobs
Forum Newbie
Posts: 15
Joined: Mon Sep 07, 2009 4:50 pm

php trouble

Post 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");
 
?>
SimonMayer
Forum Commoner
Posts: 32
Joined: Wed Sep 09, 2009 6:40 pm

Re: php trouble

Post 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.
RustyDoorknobs
Forum Newbie
Posts: 15
Joined: Mon Sep 07, 2009 4:50 pm

Re: php trouble

Post 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");
 
?>
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: php trouble

Post by jackpf »

$stats is not in the function's scope.
RustyDoorknobs
Forum Newbie
Posts: 15
Joined: Mon Sep 07, 2009 4:50 pm

Re: php trouble

Post by RustyDoorknobs »

Thanks ya ol goose!
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: php trouble

Post by jackpf »

;)
Post Reply