Naraku Posted September 24, 2008 Share Posted September 24, 2008 ok i have this script, it is suppose to query the mysql database and its suppose to look at the account table and where online is 1 it should output this info in xml format.. XML is a must.. here is the script and the error Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\bin\php\php5.2.6\statxml.php on line 68 <?php $Hostname = '192.168.xxx.xxx'; $Username = 'DB'; $Password = 'PASS'; $Database = 'characters'; // must contains characters table $RealmHostname = $Hostname; $RealmUsername = $Username; $RealmPassword = $Password; $RealmDatabase = 'realmd'; // must contains zone_coordinates and accounts table $EmuVersion = '6000'; $Owner = 'Allarius'; $ServerName = 'HellsWinter'; $ServerAddress = 'us.login.hellswinter.net'; $Patch = '2.4.3'; $Registration = 'Open'; $MaxPlayers = '300'; $XP = 'high'; $DatabaseEncoding = 'utf8'; $Output = MangosStat(); Header('Content-Type: text/xml'); // Needed only for direct generation of xml file Header('Content-Length: '.strlen($Output)); // Needed only for direct generation of xml file echo($Output); function MangosStat() { global $Hostname, $Username, $Password, $Database, $EmuVersion, $Owner, $ServerName, $ServerAddress, $Patch, $Registration, $MaxPlayers, $XP, $realm_db, $DatabaseEncoding, $RealmHostname, $RealmUsername, $RealmPassword, $RealmDatabase; $Result = '<?xml version="1.0" encoding="UTF-8"'."?>\r\n". " <server>\r\n". " <servername>".$ServerName."</servername>\r\n". " <serveraddress>".$ServerAddress."</serveraddress>\r\n". " <owner>".$Owner."</owner>\r\n". " <patch>".$Patch."</patch>\r\n". " <uptime>0 weeks 1 days 0 hours 0 mins</uptime>\r\n". " <registration>".$Registration."</registration>\r\n". " <maxplayers>".$MaxPlayers."</maxplayers>\r\n". " <xp>".$XP."</xp>\r\n". " <players>\r\n"; $realm_db = mysql_connect($RealmHostname, $RealmUsername, $RealmPassword); mysql_select_db($RealmDatabase, $realm_db); $db_result = mysql_query("SET NAMES $DatabaseEncoding", $realm_db); $mangos_db = mysql_connect($Hostname, $Username, $Password, TRUE); mysql_select_db($Database, $mangos_db); $db_result = mysql_query("SET NAMES $DatabaseEncoding", $mangos_db); $db_result = mysql_query("SELECT count(*) FROM `character` WHERE `online`='1' ORDER BY `name`", $mangos_db); $PlayersCount = mysql_fetch_row($db_result); $Result .= " <playerscount>".$PlayersCount[0]."</playerscount>\r\n"; } $db_result = mysql_query("SELECT * FROM `character` WHERE `online`='1' ORDER BY `name`", $mangos_db); while($result = mysql_fetch_array($db_result) // Get GM level by character $db_result2 = mysql_query("SELECT gmlevel FROM `account` WHERE `id`='3".$result['account']."'", $realm_db); //echo("SELECT `gmlevel` FROM `account` WHERE `id`='".$result['account']."'"); $result2 = mysql_fetch_array($db_result2); $char_data = explode(' ',$result['data']); $Result .= " <player>\r\n". " <name>".$result['name']."</name>\r\n". " <level>".$char_data[34]."</level>\r\n". " <race>".$result['race']."</race>\r\n". " <class>".$result['class']."</class>\r\n". " <zone>".get_zone_name($result['map'], $result['position_x'], $result['position_y'])."</zone>\r\n". " <map>".$result['map']."</map>\r\n". " <ip>178.12.14.2</ip>\r\n". " <plevel>".$result2['gmlevel']."</plevel>\r\n". " </player>\r\n"; } $Result .= " </players>\r\n". " </server>\r\n"; return($Result); } function get_zone_name($mapid, $x, $y) { global $realm_db; $query = mysql_query("SELECT * FROM `zone_coordinates` ORDER BY `priory`", $realm_db); $zmap = 0; while($result = mysql_fetch_array($query)) { if ($result['map']==$mapid AND $result['y_min'] < $x AND $result['y_max'] > $x AND $result['x_max'] < $y AND $result['x_min'] > $y) $zmap=$result['zone_id']; } return $zmap; } ?> Link to comment https://forums.phpfreaks.com/topic/125551-bug-in-my-php-script-ive-been-debuging-it-for-2-days-please-help/ Share on other sites More sharing options...
Lodius2000 Posted September 24, 2008 Share Posted September 24, 2008 the ?> at the end of the first line of $Result is knocking it out of php, try using ? Link to comment https://forums.phpfreaks.com/topic/125551-bug-in-my-php-script-ive-been-debuging-it-for-2-days-please-help/#findComment-649151 Share on other sites More sharing options...
DarkWater Posted September 24, 2008 Share Posted September 24, 2008 It should only be knocking it out on this syntax highlighter, not in the actual code, Lodius. The syntax highlighter is kinda buggy. You can echo ?> and be fine, as far as I know. I'll go test, one sec. EDIT: <?php echo "Testing?>test"; ?> Output: Testing?>test Link to comment https://forums.phpfreaks.com/topic/125551-bug-in-my-php-script-ive-been-debuging-it-for-2-days-please-help/#findComment-649152 Share on other sites More sharing options...
Lodius2000 Posted September 24, 2008 Share Posted September 24, 2008 ok darkwater, that makes sense, it was the first time i had seen something like that so naturally i gravitated toward it // dives back in i Still think its something in that line, because that variable goes from single to double quoted but as far as I can see still has no closing single quote because <?php $result = '<?xml version="1.0" encoding="UTF-8"'."?>\r\n"; print $result; ?> outputs \r\n"; print $result; ?> Link to comment https://forums.phpfreaks.com/topic/125551-bug-in-my-php-script-ive-been-debuging-it-for-2-days-please-help/#findComment-649157 Share on other sites More sharing options...
kenrbnsn Posted September 24, 2008 Share Posted September 24, 2008 The syntax error is occurring because you're missing a closing ")" on this line: <?php while($result = mysql_fetch_array($db_result) ?> Looking at the code, you're probably also missing an open/closing "{ }" for that while loop. Ken Link to comment https://forums.phpfreaks.com/topic/125551-bug-in-my-php-script-ive-been-debuging-it-for-2-days-please-help/#findComment-649158 Share on other sites More sharing options...
Naraku Posted September 24, 2008 Author Share Posted September 24, 2008 thank you for all the replys it fixed that problem. something so simple i knew it was a closing but i couldn't locate it anywhere but now i have more errors thease are mysql related.. if anyone could help id really appreicate it the invalid mysql result resource it speaks of is $db_result but i dont know why this syntax cant be used.. or is invalid maybe its a php extention? i dont know why it throws the cannot modify header information... Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\wamp\bin\php\php5.2.6\statxml.php on line 54 Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\bin\php\php5.2.6\statxml.php:54) in C:\wamp\bin\php\php5.2.6\statxml.php on line 21 Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\bin\php\php5.2.6\statxml.php:54) in C:\wamp\bin\php\php5.2.6\statxml.php on line 22 Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\wamp\bin\php\php5.2.6\statxml.php on line 59 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\bin\php\php5.2.6\statxml.php on line 60 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\bin\php\php5.2.6\statxml.php on line 90 <?php $Hostname = '192.168.**.***'; $Username = '*****'; $Password = '*****'; $Database = 'characters'; // must contains characters table $RealmHostname = $Hostname; $RealmUsername = $Username; $RealmPassword = $Password; $RealmDatabase = 'realmd'; // must contains zone_coordinates and accounts table $EmuVersion = '6000'; $Owner = 'Allarius'; $ServerName = 'HellsWinter'; $ServerAddress = 'us.login.hellswinter.net'; $Patch = '2.4.3'; $Registration = 'Open'; $MaxPlayers = '300'; $XP = 'high'; $DatabaseEncoding = 'utf8'; $Output = MangosStat(); Header('Content-Type: text/xml'); // Needed only for direct generation of xml file Header('Content-Length: '.strlen($Output)); // Needed only for direct generation of xml file echo($Output); function MangosStat() { global $Hostname, $Username, $Password, $Database, $EmuVersion, $Owner, $ServerName, $ServerAddress, $Patch, $Registration, $MaxPlayers, $XP, $realm_db, $DatabaseEncoding, $RealmHostname, $RealmUsername, $RealmPassword, $RealmDatabase; $Result = '<?xml version="1.0" encoding="UTF-8"'."?>\r\n". " <server>\r\n". " <servername>".$ServerName."</servername>\r\n". " <serveraddress>".$ServerAddress."</serveraddress>\r\n". " <owner>".$Owner."</owner>\r\n". " <patch>".$Patch."</patch>\r\n". " <uptime>0 weeks 1 days 0 hours 0 mins</uptime>\r\n". " <registration>".$Registration."</registration>\r\n". " <maxplayers>".$MaxPlayers."</maxplayers>\r\n". " <xp>".$XP."</xp>\r\n". " <players>\r\n"; $realm_db = mysql_connect($RealmHostname, $RealmUsername, $RealmPassword); mysql_select_db($RealmDatabase, $realm_db); $db_result = mysql_query("SET NAMES $DatabaseEncoding", $realm_db); $mangos_db = mysql_connect($Hostname, $Username, $Password, TRUE); mysql_select_db($Database, $mangos_db); $db_result = mysql_query("SET NAMES $DatabaseEncoding", $mangos_db); $db_result = mysql_query("SELECT count(*) FROM `character` WHERE `online`='1' ORDER BY `name`", $mangos_db); $PlayersCount = mysql_fetch_row($db_result); $Result .= " <playerscount>".$PlayersCount[0]."</playerscount>\r\n"; } $db_result = mysql_query("SELECT * FROM `character` WHERE `online`='1' ORDER BY `name`", $mangos_db); while($result = mysql_fetch_array($db_result)) // Get GM level by character // $db_result2 = mysql_query("SELECT gmlevel FROM `account` WHERE `id`='3".$result['account']."'", $realm_db); // echo("SELECT `gmlevel` FROM `account` WHERE `id`='".$result['account']."'"); // $result2 = mysql_fetch_array($db_result2); $char_data = explode(' ',$result['data']); $Result .= " <player>\r\n". " <name>".$result['name']."</name>\r\n". " <level>".$char_data[34]."</level>\r\n". " <race>".$result['race']."</race>\r\n". " <class>".$result['class']."</class>\r\n". " <zone>".get_zone_name($result['map'], $result['position_x'], $result['position_y'])."</zone>\r\n". " <map>".$result['map']."</map>\r\n". " <ip>178.12.14.2</ip>\r\n". " <plevel>".$result2['gmlevel']."</plevel>\r\n". " </player>\r\n"; $Result .= " </players>\r\n". " </server>\r\n"; return($Result); function get_zone_name($mapid, $x, $y) { global $realm_db; $query = mysql_query("SELECT * FROM `zone_coordinates` ORDER BY `priory`", $realm_db); $zmap = 0; while($result = mysql_fetch_array($query)) { if ($result['map']==$mapid AND $result['y_min'] < $x AND $result['y_max'] > $x AND $result['x_max'] < $y AND $result['x_min'] > $y) $zmap=$result['zone_id']; } return $zmap; } ?> Link to comment https://forums.phpfreaks.com/topic/125551-bug-in-my-php-script-ive-been-debuging-it-for-2-days-please-help/#findComment-649188 Share on other sites More sharing options...
kenrbnsn Posted September 24, 2008 Share Posted September 24, 2008 The header errors are being thrown because the first error is occurring. Fix the mysql problems first. Change each mysql_query() to something like this: <?php $q = "your query here"; $rs = mysql_query($q) or die("Problem with the query: $q<br />" . mysql_error()); ?> This will tell you why you're getting the mysql errors. Ken Link to comment https://forums.phpfreaks.com/topic/125551-bug-in-my-php-script-ive-been-debuging-it-for-2-days-please-help/#findComment-649203 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.