bwssoldya
07-16-2008, 05:35 AM
Hello everyone.
I have a little tiny problem...or a big one..depends on what u think is big and tiny...
I've got a couple codes for storing game information in an XML file.
But i got the following problem.
I'f got a form and a PHP Handler to handle the form input and store it into a XML file.
Thats all good but when you enter the game info it makes a new XML file all the time.
And thats not what i want, i want the PHP script to look at the form and look:
What console did he select in the drop-down-menu: oh he selected (example)X-Box 360 now i gotta open (example) xbox360.xml.
And that it enters new the same data only in a new field so it can store alot of games.
I have no clue what so ever how to do so.
Here are my source codes (ill post 4 but its split up in 2:
1: The code for writing the XML file to the screen and 2: inserting data into the XML file (no need for 1 realy but its a nice thing to post it))
if anyone could help.
Thanks in advance - BWSSoldya
-------!-----!-----invoer.html (HTML Form for Inserting Data)-----!----!----
<html>
<head>
<title>Game Data</title>
</head>
<body>
<p>Game Data</p>
<form method="POST" action="formhandler.php">
<input type="hidden" name="create_games" value="true">
<table>
<tr>
<td width="27%">Game Titel:</td>
<td width="73%"><input type="text" name="gameTitel" size="20"></td>
</tr>
<tr>
<td width="27%">Game Ontwikkelaar</td>
<td width="73%"><input type="text" name="gameOntwikkelaar" size="73"></td>
</tr>
<tr>
<td width="27%">Game Uitgever</td>
<td width="73%"><input type="text" name="gameUitgever" size="20"></td>
</tr>
<tr>
<td width="27%">Game PEGI (Leeftijd)</td>
<td width="73%"><input type="text" name="gamePegi" size="73"></td>
</tr>
<tr>
<td width="27%">Prijs</td>
<td width="73%"><input type="text" name="gamePrijs" size="73"></td>
</tr>
<tr>
<td width="27%">Beschrijving</td>
<td width="73%"><textarea name="gameBeschrijving"></textarea></td>
</tr>
<tr>
<td width="27%">Categorie</td>
<td width="73%"><select name="gameCategorie">
<option>First Person Shooter</option>
<option>Third Person Shooter</option>
<option>Role Playing Game</option>
<option>MMORPG</option>
<option>Actie</option>
<option>Vecht</option>
<option>Race</option>
<option>Simulatie</option>
<option>Sport</option>
<option>Adventure</option>
<option>Retro</option>
<option>Puzzle</option>
<option>Family</option></select></td>
</tr>
<tr>
<td width="27%">XML File Name</td>
<td width="73%"><select name="xmlfileConsole">
<option>PS1</option>
<option>PS2</option>
<option>PS3</option>
<option>PSP</option>
<option>XBX</option>
<option>360</option>
<option>WII</option>
<option>NDS</option>
<option>OGB</option>
<option>GBC</option>
<option>GBA</option>
<option>ASP</option>
<option>SDC</option>
<option>N64</option>
</select><input type="text" name="xmlfileName" size="20"></td>
</tr>
</table>
<p align="center">
<input type="submit" value="Submit" name="B1"></p>
</form>
</body>
</html>
----------!----!----End invoer.html-----!----!----------
----------!----!----formhandler.php (no explanation needed)------!------!------
<?php
if(isset($_POST['create_games'])){
echo "Game Data Posted";
$xmlfileName = $_POST['xmlfileName'];
$gameLink = $_POST['gameLink'];
$xmlfileConsole = $_POST['xmlfileConsole'];
$gameTitel = $_POST['gameTitel'];
$gamePegi = $_POST['gamePegi'];
$gamePrijs = $_POST['gamePrijs'];
$gameOntwikkelaar = $_POST['gameOntwikkelaar'];
$gameBeschrijving = $_POST['gameBeschrijving'];
$gameUitgever = $_POST['gameUitgever'];
$gameCategorie = $_POST['gameCategorie'];
$rootELementStart = "<game>";
$rootElementEnd = "</game>";
$xml_doc= $xml_dec;
$xml_doc .= $rootELementStart;
$xml_doc .= "<TITEL>";
$xml_doc .= $gameTitel;
$xml_doc .= "</TITEL>";
$xml_doc .= "<PEGI>";
$xml_doc .= $gamePegi;
$xml_doc .= "</PEGI>";
$xml_doc .= "<PRIJS>";
$xml_doc .= $gamePrijs;
$xml_doc .= "</PRIJS>";
$xml_doc .= "<ONTWIKKELAAR>";
$xml_doc .= $gameOntwikkelaar;
$xml_doc .= "</ONTWIKKELAAR>";
$xml_doc .= "<BESCHRIJVING>";
$xml_doc .= $gameBeschrijving;
$xml_doc .= "</BESCHRIJVING>";
$xml_doc .= "<UITGEVER>";
$xml_doc .= $gameUitgever;
$xml_doc .= "</UITGEVER>";
$xml_doc .= "<CATEGORIE>";
$xml_doc .= $gameCategorie;
$xml_doc .= "</CATEGORIE>";
$xml_doc .= "<LINK>";
$xml_doc .= $gameLink;
$xml_doc .= "</LINK>";
$xml_doc .= $rootElementEnd;
$default_dir = "xml_files/";
$default_dir .= $xmlfileName.".xml";
$fp = fopen($default_dir,'w');
$write = fwrite($fp,$xml_doc);
}
?>
---------!--------!----!---End formhandler.php------!----!---------!-------
---------!--------!----!---try1.html (To write the XML data to the screen)---!------!------!-----!----!--
<html>
<head>
<script type="text/javascript">
var xmlDoc;
if (window.ActiveXObject)
{// code for IE
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
else if (document.implementation.createDocument)
{// code for Mozilla, Firefox, Opera, etc.
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
}
xmlDoc.async=false;
xmlDoc.load("xbox360.xml");
var x=xmlDoc.getElementsByTagName("GAMES");
function show(i)
{
titel=(x[i].getElementsByTagName("TITEL")[0].childNodes[0].nodeValue);
beschrijving=(x[i].getElementsByTagName("BESCHRIJVING")[0].childNodes[0].nodeValue);
pegi=(x[i].getElementsByTagName("PEGI")[0].childNodes[0].nodeValue);
prijs=(x[i].getElementsByTagName("PRIJS")[0].childNodes[0].nodeValue);
ontwikkelaar=(x[i].getElementsByTagName("ONTWIKKELAAR")[0].childNodes[0].nodeValue);
link=(x[i].getElementsByTagName("LINK")[0].childNodes[0].nodeValue);
txt="Titel: "+titel+"<br />Beschrijving: "+beschrijving+"<br />PEGI: "+pegi+"<br />Prijs: "+prijs+"<br />Ontwikkelaar: "+ontwikkelaar+"<br/><br/>Klik <a href='"+link+".php'>hier</a> voor meer informatie over "+titel ;
document.getElementById("show").innerHTML=txt;
}
</script>
</head>
<body>
<div id='show'>
Click on one of the table rows to display the full album information.
</div>
<br />
<script type="text/javascript">
document.write("<table border='1'>");
for (var i=0;i<x.length;i++)
{
document.write("<tr onclick='show(" + i + ")'>");
document.write("<td>");
document.write(x[i].getElementsByTagName("TITEL")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(x[i].getElementsByTagName("PRIJS")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("</tr>");
}
document.write("</table>");
</script>
</body>
</html>
-------!-----!------!------!---End try1.html----!----!-----!-----!----
------!----!------!-----!----!-xbox360.xml (the xmlfile i added these games manualy)----!-!-!----!-!-!-----!----!--
<XBX360>
<GAMES>
<TITEL>Grand Theft Auto IV</TITEL>
<BESCHRIJVING>Het nieuwste deel van de Grand Theft Auto (GTA) Series!!</BESCHRIJVING>
<PEGI>18</PEGI>
<PRIJS>50.00</PRIJS>
<ONTWIKKELAAR>RockStar</ONTWIKKELAAR>
<LINK>GTAIVX360</LINK>
</GAMES>
<GAMES>
<TITEL>Halo 3</TITEL>
<BESCHRIJVING>Het nieuwste deel van de Halo Series!!</BESCHRIJVING>
<PEGI>18</PEGI>
<PRIJS>50.00</PRIJS>
<ONTWIKKELAAR>RockStar</ONTWIKKELAAR>
<LINK>H3X360</LINK>
</GAMES>
</XBX360>
-----!------!-------!----End xbox360.xml-----!------!----!--------!
I have a little tiny problem...or a big one..depends on what u think is big and tiny...
I've got a couple codes for storing game information in an XML file.
But i got the following problem.
I'f got a form and a PHP Handler to handle the form input and store it into a XML file.
Thats all good but when you enter the game info it makes a new XML file all the time.
And thats not what i want, i want the PHP script to look at the form and look:
What console did he select in the drop-down-menu: oh he selected (example)X-Box 360 now i gotta open (example) xbox360.xml.
And that it enters new the same data only in a new field so it can store alot of games.
I have no clue what so ever how to do so.
Here are my source codes (ill post 4 but its split up in 2:
1: The code for writing the XML file to the screen and 2: inserting data into the XML file (no need for 1 realy but its a nice thing to post it))
if anyone could help.
Thanks in advance - BWSSoldya
-------!-----!-----invoer.html (HTML Form for Inserting Data)-----!----!----
<html>
<head>
<title>Game Data</title>
</head>
<body>
<p>Game Data</p>
<form method="POST" action="formhandler.php">
<input type="hidden" name="create_games" value="true">
<table>
<tr>
<td width="27%">Game Titel:</td>
<td width="73%"><input type="text" name="gameTitel" size="20"></td>
</tr>
<tr>
<td width="27%">Game Ontwikkelaar</td>
<td width="73%"><input type="text" name="gameOntwikkelaar" size="73"></td>
</tr>
<tr>
<td width="27%">Game Uitgever</td>
<td width="73%"><input type="text" name="gameUitgever" size="20"></td>
</tr>
<tr>
<td width="27%">Game PEGI (Leeftijd)</td>
<td width="73%"><input type="text" name="gamePegi" size="73"></td>
</tr>
<tr>
<td width="27%">Prijs</td>
<td width="73%"><input type="text" name="gamePrijs" size="73"></td>
</tr>
<tr>
<td width="27%">Beschrijving</td>
<td width="73%"><textarea name="gameBeschrijving"></textarea></td>
</tr>
<tr>
<td width="27%">Categorie</td>
<td width="73%"><select name="gameCategorie">
<option>First Person Shooter</option>
<option>Third Person Shooter</option>
<option>Role Playing Game</option>
<option>MMORPG</option>
<option>Actie</option>
<option>Vecht</option>
<option>Race</option>
<option>Simulatie</option>
<option>Sport</option>
<option>Adventure</option>
<option>Retro</option>
<option>Puzzle</option>
<option>Family</option></select></td>
</tr>
<tr>
<td width="27%">XML File Name</td>
<td width="73%"><select name="xmlfileConsole">
<option>PS1</option>
<option>PS2</option>
<option>PS3</option>
<option>PSP</option>
<option>XBX</option>
<option>360</option>
<option>WII</option>
<option>NDS</option>
<option>OGB</option>
<option>GBC</option>
<option>GBA</option>
<option>ASP</option>
<option>SDC</option>
<option>N64</option>
</select><input type="text" name="xmlfileName" size="20"></td>
</tr>
</table>
<p align="center">
<input type="submit" value="Submit" name="B1"></p>
</form>
</body>
</html>
----------!----!----End invoer.html-----!----!----------
----------!----!----formhandler.php (no explanation needed)------!------!------
<?php
if(isset($_POST['create_games'])){
echo "Game Data Posted";
$xmlfileName = $_POST['xmlfileName'];
$gameLink = $_POST['gameLink'];
$xmlfileConsole = $_POST['xmlfileConsole'];
$gameTitel = $_POST['gameTitel'];
$gamePegi = $_POST['gamePegi'];
$gamePrijs = $_POST['gamePrijs'];
$gameOntwikkelaar = $_POST['gameOntwikkelaar'];
$gameBeschrijving = $_POST['gameBeschrijving'];
$gameUitgever = $_POST['gameUitgever'];
$gameCategorie = $_POST['gameCategorie'];
$rootELementStart = "<game>";
$rootElementEnd = "</game>";
$xml_doc= $xml_dec;
$xml_doc .= $rootELementStart;
$xml_doc .= "<TITEL>";
$xml_doc .= $gameTitel;
$xml_doc .= "</TITEL>";
$xml_doc .= "<PEGI>";
$xml_doc .= $gamePegi;
$xml_doc .= "</PEGI>";
$xml_doc .= "<PRIJS>";
$xml_doc .= $gamePrijs;
$xml_doc .= "</PRIJS>";
$xml_doc .= "<ONTWIKKELAAR>";
$xml_doc .= $gameOntwikkelaar;
$xml_doc .= "</ONTWIKKELAAR>";
$xml_doc .= "<BESCHRIJVING>";
$xml_doc .= $gameBeschrijving;
$xml_doc .= "</BESCHRIJVING>";
$xml_doc .= "<UITGEVER>";
$xml_doc .= $gameUitgever;
$xml_doc .= "</UITGEVER>";
$xml_doc .= "<CATEGORIE>";
$xml_doc .= $gameCategorie;
$xml_doc .= "</CATEGORIE>";
$xml_doc .= "<LINK>";
$xml_doc .= $gameLink;
$xml_doc .= "</LINK>";
$xml_doc .= $rootElementEnd;
$default_dir = "xml_files/";
$default_dir .= $xmlfileName.".xml";
$fp = fopen($default_dir,'w');
$write = fwrite($fp,$xml_doc);
}
?>
---------!--------!----!---End formhandler.php------!----!---------!-------
---------!--------!----!---try1.html (To write the XML data to the screen)---!------!------!-----!----!--
<html>
<head>
<script type="text/javascript">
var xmlDoc;
if (window.ActiveXObject)
{// code for IE
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
else if (document.implementation.createDocument)
{// code for Mozilla, Firefox, Opera, etc.
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
}
xmlDoc.async=false;
xmlDoc.load("xbox360.xml");
var x=xmlDoc.getElementsByTagName("GAMES");
function show(i)
{
titel=(x[i].getElementsByTagName("TITEL")[0].childNodes[0].nodeValue);
beschrijving=(x[i].getElementsByTagName("BESCHRIJVING")[0].childNodes[0].nodeValue);
pegi=(x[i].getElementsByTagName("PEGI")[0].childNodes[0].nodeValue);
prijs=(x[i].getElementsByTagName("PRIJS")[0].childNodes[0].nodeValue);
ontwikkelaar=(x[i].getElementsByTagName("ONTWIKKELAAR")[0].childNodes[0].nodeValue);
link=(x[i].getElementsByTagName("LINK")[0].childNodes[0].nodeValue);
txt="Titel: "+titel+"<br />Beschrijving: "+beschrijving+"<br />PEGI: "+pegi+"<br />Prijs: "+prijs+"<br />Ontwikkelaar: "+ontwikkelaar+"<br/><br/>Klik <a href='"+link+".php'>hier</a> voor meer informatie over "+titel ;
document.getElementById("show").innerHTML=txt;
}
</script>
</head>
<body>
<div id='show'>
Click on one of the table rows to display the full album information.
</div>
<br />
<script type="text/javascript">
document.write("<table border='1'>");
for (var i=0;i<x.length;i++)
{
document.write("<tr onclick='show(" + i + ")'>");
document.write("<td>");
document.write(x[i].getElementsByTagName("TITEL")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(x[i].getElementsByTagName("PRIJS")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("</tr>");
}
document.write("</table>");
</script>
</body>
</html>
-------!-----!------!------!---End try1.html----!----!-----!-----!----
------!----!------!-----!----!-xbox360.xml (the xmlfile i added these games manualy)----!-!-!----!-!-!-----!----!--
<XBX360>
<GAMES>
<TITEL>Grand Theft Auto IV</TITEL>
<BESCHRIJVING>Het nieuwste deel van de Grand Theft Auto (GTA) Series!!</BESCHRIJVING>
<PEGI>18</PEGI>
<PRIJS>50.00</PRIJS>
<ONTWIKKELAAR>RockStar</ONTWIKKELAAR>
<LINK>GTAIVX360</LINK>
</GAMES>
<GAMES>
<TITEL>Halo 3</TITEL>
<BESCHRIJVING>Het nieuwste deel van de Halo Series!!</BESCHRIJVING>
<PEGI>18</PEGI>
<PRIJS>50.00</PRIJS>
<ONTWIKKELAAR>RockStar</ONTWIKKELAAR>
<LINK>H3X360</LINK>
</GAMES>
</XBX360>
-----!------!-------!----End xbox360.xml-----!------!----!--------!