|
|
|
PHP + XML ครับช่วยหน่อยครับ ถ้าผมมี form การกรอกข้อมูล เมื่อ กด submit แล้วจะนำตัวแปรข้อมูลที่ได้มา |
|
|
|
|
|
|
|
Code (PHP)
<?php
function writeXML($xml)
{
$fp = fopen('xml5.xml', 'w+');
fwrite($fp,$xml);
fclose($fp);
}
if(isset($submit))
{
$album = $_POST['album'];
$track = $_POST['track'];
$desc = $_POST['desc'];
// Set the content type to be XML, so that the browser will recognise it as XML.
header( "content-type: application/xml; charset=utf-8" );
// "Create" the document.
$xml = new DOMDocument( "1.0", "utf-8" );
// Create some elements.
$xml_album = $xml->createElement( "Album" );
// Create another element, just to show you can add any (realistic to computer) number of sublevels.
$xml_name = $xml->createElement( "Name",$album );
$xml_track = $xml->createElement( "Track", $track );
$xml_note = $xml->createElement( "Description", $desc );
// Append the whole bunch.
$xml_album->appendChild( $xml_name );
$xml_album->appendChild( $xml_note );
$xml_album->appendChild( $xml_track );
// Append the DOMXML.
$xml->appendChild( $xml_album );
// Parse the XML.
$text = $xml->saveXML();
print $text;
writeXML($text);
}
else
{
?>
<form method="post" name="formxml" action="<?=$SERVER_['PHP_SELF'] ?>">
Album Name : <input type="text" name="album"></br>
Track Name : <input type="text" name="track"></br>
Track Description : <input type="text" name="desc"></br>
<input type="submit" name="submit" value=" Add "></br>
</form>
<?
}
?>
|
|
|
|
|
Date :
2009-09-15 02:06:32 |
By :
extenser |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากครับ
|
|
|
|
|
Date :
2009-09-15 10:06:21 |
By :
pjgunner |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|