View Full Version : flex to database.
malcomhfc
06-10-2009, 03:28 PM
Hey everyone. Im trying to find away to, when someone fill's out a form and push enter, the info is stored into a sql database of which i can display the data, say so someone can view using a php script.
The part im stuck at is how i manage after submit button being pushed, flex connects to a sql database and uploads into the specified tables.
If that's to complicated, is there a easy feature like send info by mail?
Im new to flex and im looking to use this feature in one of my apps im creating :)
Thanks in advance,
Malcom
loki421
06-14-2009, 09:01 PM
Hi,
You'd use a function to send the relevant fields back to the server where it's handled.
here's an example:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
private function insertRecord(event:MouseEvent):void
{
ro.InsertRecord
(someValue.text,
someMore.text,
bitMore.text);
Alert.show('You have successfully added this record.');
}
private function myFaultHandler(event:FaultEvent):void
{
Alert.show(event.fault.faultString, event.fault.faultCode);
}
private function myResultHandler(event:ResultEvent):void
{
//whatever result you want in here....
}
]]>
</mx:Script>
<mx:RemoteObject id="ro" destination="ColdFusion" source="flex3.myCFC" showBusyCursor="true" >
<mx:method name="InsertRecord" result="myResultHandler(event)" fault="myFaultHandler(event)" />
</mx:RemoteObject>
<mx:HBox width="392" height="113">
<mx:VBox width="100" height="100" horizontalAlign="right">
<mx:Label text="Some data"/>
<mx:Label text="some more data"/>
<mx:Label text="bit more data"/>
</mx:VBox>
<mx:VBox width="259" height="100">
<mx:TextInput id="someValue"/>
<mx:TextInput id="someMore"/>
<mx:TextInput id="bitMore"/>
</mx:VBox>
</mx:HBox>
<mx:Button label="Add record" click="insertRecord(event)"/>
</mx:Application>
That's just a basic app, you'd then handle the data on the server, this example is using ColdFusion, but all you have to change is the Remote Object or change it to a http request.
If you were using CF to handle the data it would go something like this:
<cffunction name="InsertRecord" access="remote" returntype="Any">
<cfargument name="someValue" type="string" required="yes">
<cfargument name="someMore" type="string" required="yes">
<cfargument name="bitMore" type="string" required="yes">
<cfquery name="qInsert" datasource="#myDSN#">
INSERT INTO #myTable# (column1,
column2,
column3)
VALUES (
'#arguments.someValue#',
'#arguments.someMore#',
'#arguments.bitMore#')
</cfquery>
</cffunction>
That would obvioulsy be in your CFC.
Anyway, hope this sheds some light on the subject for you :D
I'm actually writing an application which does the very thing you are trying to achieve. Instead of using ActionScript to connect to the database, however, I used PHP. The Flex frontend sends data to the PHP script using <mx:HTTPService>.
This is the part I'm still working on: the PHP script sends back a response to the Flex application using XML, telling the application what happened (i.e. if the data injection was successful, if it failed, if there are any fields which are left blank etc.)
But it definitely is possible. If you want to see the source, just ask.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.