View Full Version : Using a form result as a variable to parse XML

09-29-2008, 01:38 PM
Hi there,

I will mention this now as it will hurt me later on if I don't!! I'm a COMPLETE newbie when it comes to coding PHP so I'm asking for your time and help and anything you can provide is MUCH appreciated.

I'll start from scratch with my set-up:
:: Drupal CMS
:: PHP 5.0+
:: A Page on Drupal which is a form whereby a user can type in a name
:: An XML file which is created from the above name (this is an external feed kindly provided by another user)
:: A Page on Drupal to list the results after parsing an XML file

This is where I've got a problem - how on Earth do I do this? I've tried various experimental ways myself to no avail, so I'm hoping any kind members of this community would be able to help.

It seems a particular problem that I'm using the Drupal CMS. I have investigated as much as possible and when using a form it has to be pointed at a .php page which will then process the entry into the form and use it accordingly - but with Drupal creating a page isn't as simple as that so I'm assuming the only way I can make a page a definate .php extention is to use a php include to include a .php hosted on my server. If I do that however, how can I make the form go to the page which holds the php include and execute the include appropriately?

I'll show you what I have so far:

The Form Page:

<form action="lookup.php" method="POST">
Enter PSN: <input type="text" name="name">
<input type="submit" value="Search...">

The results page

$PSN = $_POST["name"])
$url = "http://myhawk.org/action/action.html?handle=<?php print $PSN ?>;";
$xml = simplexml_load_file($url) or die("Unable to process, please try later.");
$rank = $xml->response->rank;
$rankImage = $xml->response->rankImage;
$globalGamePoints = $xml->response->globalGamePoints;
$globalTeamScore = $xml->response->globalTeamScore;
$globalCombatScore = $xml->response->globalCombatScore;
$globalBonusScore = $xml->response->globalBonusScore;
$globalTime = $xml->response->globalTime;
$globalKills = $xml->response->globalKills;
$globalDeaths = $xml->response->globalDeaths;
$globalKdr = $xml->response->globalKdr;
$globalAccuracy = $xml->response->globalAccuracy;
$globalWins = $xml->response->globalWins;
$globalLosses = $xml->response->globalLosses;
$globalWinLossRatio = $xml->response->globalWinLossRatio;
$globalScorePerMinute = $xml->response->globalScorePerMinute;
$globalDmScore = $xml->response->globalDmScore;
$globalTdmScore = $xml->response->globalTdmScore;
$globalHeroScore = $xml->response->globalHeroScore;
$globalColScore = $xml->response->globalColScore;
$globalMilesWalked = $xml->response->globalMilesWalked;
$globalMilesDriven = $xml->response->globalMilesDriven;
$globalMilesFlown = $xml->response->globalMilesFlown;
$globalGamePointsRank = $xml->response->globalGamePointsRank;
$globalTeamScoreRank = $xml->response->globalTeamScoreRank;
$globalCombatScoreRank = $xml->response->globalCombatScoreRank;
$globalBonusScoreRank = $xml->response->globalBonusScoreRank;
$globalTimeRank = $xml->response->globalTimeRank;
$globalKillsRank = $xml->response->globalKillsRan
$globalDeathsRank = $xml->response->globalDeathsRank;
$globalKdrRank = $xml->response->globalKdrRank;
$globalAccuracyRank = $xml->response->globalAccuracyRank;
$globalWinsRank = $xml->response->globalWinsRank;
$globalLossesRank = $xml->response->globalLossesRank;
$globalWinLossRatioRank = $xml->response->globalWinLossRatioRank;
$globalScorePerMinuteRank = $xml->response->globalScorePerMinuteRank;
$globalDmScoreRank = $xml->response->globalDmScoreRank;
$globalTdmScoreRank = $xml->response->globalTdmScoreRank;
$globalHeroScoreRank = $xml->response->globalHeroScoreRank;
$globalColScoreRank = $xml->response->globalColScoreRank;
$globalMilesWalkedRank = $xml->response->globalMilesWalkedRank;
$globalMilesDrivenRank = $xml->response->globalMilesDrivenRank;
$globalMilesFlownRank = $xml->response->globalMilesFlownRank;
$dailyGamePoints = $xml->response->dailyGamePoints;
$dailyTeamScore = $xml->response->dailyTeamScore;
$dailyCombatScore = $xml->response->dailyCombatScore;
$dailyBonusScore = $xml->response->dailyBonusScore;
$dailyTime = $xml->response->dailyTime;
$dailyKills = $xml->response->dailyKills;
$dailyDeaths = $xml->response->dailyDeaths;
$dailyKdr = $xml->response->dailyKdr;
$dailyAccuracy = $xml->response->dailyAccuracy;
$dailyWins = $xml->response->dailyWins;
$dailyLosses = $xml->response->dailyLosses;
$dailyWinLossRatio = $xml->response->dailyWinLossRatio;
$dailyScorePerMinute = $xml->response->dailyScorePerMinute;
$dailyDmScore = $xml->response->dailyDmScore;
$dailyTdmScore = $xml->response->dailyTdmScore;
$dailyHeroScore = $xml->response->dailyHeroScore;
$dailyColScore = $xml->response->dailyColScore;
$dailyMilesWalked = $xml->response->dailyMilesWalked;
$dailyMilesDriven = $xml->response->dailyMilesDriven;
$dailyMilesFlown = $xml->response->dailyMilesFlown;
$dailyGamePointsRank = $xml->response->dailyGamePointsRank;
$dailyTeamScoreRank = $xml->response->dailyTeamScoreRank;
$dailyCombatScoreRank = $xml->response->dailyCombatScoreRank;
$dailyBonusScoreRank = $xml->response->dailyBonusScoreRank;
$dailyTimeRank = $xml->response->dailyTimeRank;
$dailyKillsRank = $xml->response->dailyKillsRank;
$dailyDeathsRank = $xml->response->dailyDeathsRank;
$dailyKdrRank = $xml->response->dailyKdrRank;
$dailyAccuracyRank = $xml->response->dailyAccuracyRank;
$dailyWinsRank = $xml->response->dailyWinsRank;
$dailyLossesRank = $xml->response->dailyLossesRank;
$dailyWinLossRatioRank = $xml->response->dailyWinLossRatioRank;
$dailyScorePerMinuteRank = $xml->response->dailyScorePerMinuteRank;
$dailyDmScoreRank = $xml->response->dailyDmScoreRank;
$dailyTdmScoreRank = $xml->response->dailyTdmScoreRank;
$dailyHeroScoreRank = $xml->response->dailyHeroScoreRank;
$dailyColScoreRank = $xml->response->dailyColScoreRank;
$dailyMilesWalkedRank = $xml->response->dailyMilesWalkedRank;
$dailyMilesDrivenRank = $xml->response->dailyMilesDrivenRank;
$dailyMilesFlownRank = $xml->response->dailyMilesFlownRank;

Test1: <?php echo $rank; ?><br/>
Test2: <?php echo $globalGamePoints; ?>

However this doesn't work; the results page just comes up blank. I'm definitely running PHP5+ so the above simplexml parse should work however I'm not sure if I'm running it correctly. The URL you see which hosts the file is the URL I need to use and the text after "action.html?handle=" needs to contain whatever was entered into the form then finish with "&key=yallobzff7".

If you enter an invalid entry, the XML page returns an error code too so I will also be looking for a way to pick up on that error should an invalid entry be made.

VERY many thanks to anyone who can help me, I can guarantee you your time, effort and help is as appreciated as it could possibly be.