Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Posting XML to a Database

Community Expert ,
Oct 25, 2010 Oct 25, 2010

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.

TOPICS
ActionScript
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2010 Oct 25, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 25, 2010 Oct 25, 2010

Thanks Ned, I've always used PHP, just wanted to make sure I wasn't missing an easier route.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2010 Oct 25, 2010

You're welcome

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 26, 2010 Oct 26, 2010

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 26, 2010 Oct 26, 2010

How do you post? Show the code.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 26, 2010 Oct 26, 2010

Also, what is the server error?


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 26, 2010 Oct 26, 2010

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)

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 26, 2010 Oct 26, 2010

I think you need to use URLVariables:

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/URLVariables.html

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 26, 2010 Oct 26, 2010

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 26, 2010 Oct 26, 2010
LATEST

You are welcome.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 26, 2010 Oct 26, 2010

And, maybe, contentType


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 26, 2010 Oct 26, 2010

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"?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines