I have written a flex application that sends XML to a php script which will then be inserted into a databse.
The php script works fine when I am loading the XML from a static file but when I try and load the XML from the post variables it stops working.
I have written the post data to a text file and it is coming through.
My php file is as follows
<?php
//Connect to the database
$link = mysql_connect("localhost", "root", "new_password") or die(mysql_error());
//Select the database
mysql_select_db("flex_tests", $link) or die(mysql_error());
//Create a new dom document
$doc = new DOMDocument();
//Load the xml
//$doc->load('species.xml');
$post_data = $_POST['species'];
$species_info = $doc->getElementsByTagName("speciesInfo");
foreach($species_info as $info) {
$common_name_node = $info->getElementsByTagName("commonName");
$common_name = $common_name_node->item(0)->nodeValue;
$scientific_name_node = $info->getElementsByTagName("scientificName");
$scientific_name = $scientific_name_node->item(0)->nodeValue;
$sql = "INSERT INTO `species` (`commonName`, `scientificName`) VALUES ('".mysql_real_escape_string($common_name)."', '".mysql_real_escape_string($scientific_name)."');";
//echo "<p>$sql</p>";
$result = mysql_query($sql) or die(mysql_error());
}
//Open the text file and dump the print_r of the post in it
$myFile = "test.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
//$stringData = "Bobby Bopper\n";
$post_details = "";
foreach($_POST as $key => $value) {
$post_details .= "$key = $value \n\n";
}
fwrite($fh, $post_details);
//$stringData = "Tracy Tanner\n";
//fwrite($fh, $stringData);
fclose($fh);
?>
The XML it prints to the text file is
species = <species><speciesInfo><commonName>Basking Shark2</commonName><scientificName>Sharkus Baskius2</scientificName><defaultImage width="600" height="400">baskshark2.jpg</defaultImage></speciesInfo><speciesInfo><commonName>Dolphin2</commonName><scientificName>Flippinium Dolphius2</scientificName><defaultImage width="600" height="400">dolphin2.jpg</defaultImage></speciesInfo></species>
Thanks for any help or suggestions