john6384 Posted November 5, 2007 Share Posted November 5, 2007 Hello, first of all I have some AJAX that POST's a PHP files output like so: //XMLResults is a string of XML ... XMLResults += '/>'; var objHTTP, strResult; objHTTP=new XMLHttpRequest(); objHTTP.open('POST', "PutData.php", false); objHTTP.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); objHTTP.overrideMimeType('text/html'); objHTTP.send("xml=" + xmlDoc); strResult=objHTTP.responseText; Now in PutData.php I need to convert from XML to SQL. What is the best way of doing this? I have this to get the data from the POST: foreach($_POST as $key => $data){ mysql_query(SQLFromXML($data)) or die (mysql_error()); } Then I will need a function to do the work - please describe the structure of this and give any hints or point me to code. Thankyou Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 5, 2007 Share Posted November 5, 2007 there isn't one that I know of, but you will need to use some sort of usage with the Key and stuff. Quote Link to comment Share on other sites More sharing options...
john6384 Posted November 5, 2007 Author Share Posted November 5, 2007 Well this function was given to me but I dont think its complete and also it gives back in the alert in the AJAX - query was empty. function SQLFromXML($doc){ global $sqlString; //Initialize the XML parser $parser=xml_parser_create(); //Function to use at the start of an element function start($parser,$element_name,$element_attrs) { global $sqlString; $sqlString="insert into " . $element_name . "("; $seperator=""; foreach ($element_attrs as $key => $value) { $sqlString=$sqlString . $seperator . $key; $seperator=","; } $sqlString=$sqlString . ") values("; $seperator=""; foreach ($element_attrs as $key => $value) { $sqlString=$sqlString . $seperator . "'" . $value . "'"; $seperator=","; } $sqlString=$sqlString . ")"; } //Function to use at the end of an element function stop($parser,$element_name) { // echo "<br />"; } //Function to use when finding character data function char($parser,$data) { // echo $data; } //Specify element handler xml_set_element_handler($parser,"start","stop"); //Specify data handler xml_set_character_data_handler($parser,"char"); //parse data xml_parse($parser,$doc); //Free the XML parser xml_parser_free($parser); return $sqlString; } Any comments on why this is returned in the alert? Cheers Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.