Copy link to clipboard
Copied
I have an ongoing project that outputs xml data to my client's server via a php script. The client would like to move the XML into a database, and their database company has instructed me to POST the XML to a web address with a form field linked to the database. This produces a server error (if I manually paste the XML into the form it works). In order to get this to work, does there need to be a PHP or some other server side script between Flash and the database? Thanks.
Copy link to clipboard
Copied
Yes, Flash cannot interact with a database directly, and PHP is one of the most commonly used middlemen for accomplishing the back and forth. If you Google "AS3 PHP mySQL tutorial" you'll probably find some useful tutorials.
Copy link to clipboard
Copied
Thanks Ned, I've always used PHP, just wanted to make sure I wasn't missing an easier route.
Copy link to clipboard
Copied
You're welcome
Copy link to clipboard
Copied
It turns out that the database company is using a C# program to connect to the db with a simple html form to capture the XML as the frontend. They were assuming if I did an HTTP POST via Flash to the form page it would work—it does work if I manually paste the XML into the HTM page. My Flash URLRequest POST method does not—Safari's Activity panel shows an internal server error. Is there any way this would be possible or would we still need a simple PHP script to relay the post to the HTML page?
Copy link to clipboard
Copied
How do you post? Show the code.
Copy link to clipboard
Copied
Also, what is the server error?
Copy link to clipboard
Copied
Below is my send function, trace(sxml) returns the xml ok.
My httpStatusHandler returns an error code 500
private var loader:URLLoader = new URLLoader();
private var xmlrequest:URLRequest = new URLRequest();
public function sendXML(sxml:XML):void {
loader.addEventListener(IOErrorEvent.IO_ERROR, outputError);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityError);
loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
xmlrequest.url=databaseurl;
xmlrequest.method = URLRequestMethod.POST;
xmlrequest.data = sxml;
loader.load(xmlrequest);
trace(sxml)
}
Copy link to clipboard
Copied
I think you need to use URLVariables:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/URLVariables.html
Copy link to clipboard
Copied
Got it to work with URLVariables. I needed to match the variable to the name of the field in the HTML page—datapoint needed to be data. Thanks for your help!
Copy link to clipboard
Copied
You are welcome.
Copy link to clipboard
Copied
And, maybe, contentType
Copy link to clipboard
Copied
I tried this and it returns the same error:
private var loader:URLLoader = new URLLoader();
private var xmlrequest:URLRequest = new URLRequest();
private var urlvars:URLVariables=new URLVariables();
public function sendXML(sxml:XML):void {
loader.addEventListener(IOErrorEvent.IO_ERROR, outputError);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityError);
loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
urlvars.datapoint=sxml;
xmlrequest.url=databaseurl;
xmlrequest.method = URLRequestMethod.POST;
xmlrequest.data = urlvars;
loader.load(xmlrequest);
trace(urlvars.datapoint)
}
The documentation for contentType states that it should be left at the default if the data is a URLVariable. Maybe I should go back to sending the raw xml as the data and setting the contentType to XML. Would that be "text/xml"?