Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    flex to database.

    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

  • #2
    Regular Coder
    Join Date
    Feb 2009
    Location
    Worcester
    Posts
    172
    Thanks
    13
    Thanked 6 Times in 6 Posts
    Hi,

    You'd use a function to send the relevant fields back to the server where it's handled.

    here's an example:

    Code:
    <?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:
    Code:
    <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

  • #3
    Regular Coder BWiz's Avatar
    Join Date
    Mar 2006
    Location
    Sol System
    Posts
    471
    Thanks
    7
    Thanked 21 Times in 21 Posts
    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.
    BWiz :: Happy Coding!
    2006
    2007 2008 2009
    2010 2011
    Irrational numbers make no sense.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •