
Untitled
By: a guest on
Jul 17th, 2012 | syntax:
None | size: 1.12 KB | hits: 12 | expires: Never
XML with mySQL and DOM
Input data: "davidjmorin"
Data inserted: "http://someurl.com/davidjmorin"
<?
//header('Content-type: text/xml');
$link = mysql_connect('localhost','root','IhaveAlLthEanSwers2012!');
mysql_select_db('bb_links');
$sql = "Select * from `links`";
$run = mysql_query($sql, $link);
if( $run && mysql_num_rows( $run ) ) {
$doc = new DOMDocument( '1.0' );
$doc->formatOutput = true;
$doc->preserveWhiteSpace = true;
$root = $doc->createElement( 'data' );
$doc->appendChild( $root );
while( ( $fetch = mysql_fetch_assoc( $run ) )!== false ) {
$node = $doc->createElement( 'channel' );
$root->appendChild( $node );
foreach( $fetch as $key => $value ) {
createNodes( $key, $value, $doc, $node );
}
}
$doc->save("thelinks.xml");
}
//$node = "channel";
function createNodes( $key, $value, $doc, $node ) {
$key = $doc->createElement( $key );
$node->appendChild( $key );
$key->appendChild( $doc->createTextNode( $value ) );
}
?>
<?php
$url_name = "http://www.example.com/";
$data = $_POST['name']; //davidjmorin
$data_to_insert = $url_name . $data;
//Insert data into database
?>