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

Posting XML to a Database

Community Expert ,
Oct 25, 2010 Oct 25, 2010

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.

TOPICS
ActionScript

Views

1.1K

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

You're welcome

Votes

Translate

Translate

Report

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

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?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

How do you post? Show the code.


Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Also, what is the server error?


Votes

Translate

Translate

Report

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

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)

}

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

I think you need to use URLVariables:

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

Votes

Translate

Translate

Report

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

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!

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

You are welcome.


Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

And, maybe, contentType


Votes

Translate

Translate

Report

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

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

Votes

Translate

Translate

Report

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