Skip navigation
DashawnPD242
Currently Being Moderated

Save Changes to MySQL After Updating

Mar 30, 2013 12:42 PM

Tags: #air #flex-mobile #flex #xml #flex-4.6 #air3 #datagrid #4.5.1 #flex4.5 #flex4.6 #flashbuilder4.6 #xmlcollectionlist

I need a solution for saving text information after i update it. I am using a xml datagrid, which pulls the information. I use a popup window which allows me to edit the information. I can successfully update the xml datagrid from this popup window, but how do i save this updated information into MySQL Database? The update.php file executes perfect when using a php form. 

 

My flex 4 code below:-

 

<?xml version="1.0" encoding="utf-8"?>

<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"

                                        xmlns:reservationsservice="services.reservationss ervice.*"

                                        close="ttlWndw2_close(event);" creationComplete="centerWindow()" layout="vertical"

                                        showCloseButton="true" title="Edit Booking">

          <mx:Form width="100%" height="100%">

                    <mx:FormItem label="Vehicle Type">

                              <mx:TextInput id="typeofvehicle" text="{dg.typeofvehicle}"/>

                    </mx:FormItem>

                    <mx:FormItem label="No. Of Vehicles" >

                              <mx:TextInput id="howmanyvehicles" text="{dg.howmanyvehicles}"/>

                    </mx:FormItem>

                    <mx:FormItem label="Chauffeur">

                              <mx:TextInput id="chauffeur" text="{dg.chauffeur}"/>

                    </mx:FormItem>

                    <mx:FormItem label="Payment Method" >

                              <mx:TextInput id="paymentmethod" text="{dg.paymentmethod}"/>

                    </mx:FormItem>

                    <mx:FormItem label="To">

                              <mx:TextInput id="goingto" text="{dg.goingto}"/>

                    </mx:FormItem>

                    <mx:FormItem label="From" >

                              <mx:TextInput id="goingfrom" text="{dg.goingfrom}"/>

                    </mx:FormItem>

                    <mx:FormItem label="Reception" >

                              <mx:TextInput id="reception" text="{dg.reception}"/>

                    </mx:FormItem>

                    <mx:FormItem label="Name of Passengers">

                              <mx:TextInput id="passengernames" text="{dg.passengernames}"/>

                    </mx:FormItem>

                    <mx:FormItem label="No. of Passengers">

                              <mx:TextInput id="numberofpassengers" text="{dg.numberofpassengers}"/>

                    </mx:FormItem>

                    <mx:FormItem label="Venue">

                              <mx:TextInput id="church" text="{dg.church}"/>

                    </mx:FormItem>

 

 

          </mx:Form>

          <mx:HBox width="100%">

                    <mx:Button id="savechanges" label="Save" click="SaveChanges(event);"/>

                    <mx:Button id="updatechanges" label="Update" click="UpDateChanges(event);"/>

                    <mx:Button label="Close" click="closeWindow()"/>

          </mx:HBox>

 

          <mx:Script>

                    <![CDATA[

                              import mx.controls.Alert;

                              import mx.core.IFlexDisplayObject;

                              import mx.events.CloseEvent;

                              import mx.managers.PopUpManager;

 

                              [Bindable]

            public var dg:Object;

                              private var objSend:Object = new Object;

 

                              protected function ttlWndw2_close(evt:CloseEvent):void {

                                        PopUpManager.removePopUp(evt.currentTarget as IFlexDisplayObject);

                              }

 

                              private function centerWindow():void {

 

                                        PopUpManager.centerPopUp(this);

 

                              }

 

                              private function closeWindow():void{

 

                                        PopUpManager.removePopUp(this);

                              }

 

 

 

                              protected function UpDateChanges(event:MouseEvent):void{

 

                                        // update mysql database

                                        dg.chauffeur = chauffeur.text;

                                        dg.howmanyvehicles = howmanyvehicles.text;

                                        dg.typeofvehicle = typeofvehicle.text;

                                        dg.paymentmethod = paymentmethod.text;

                                        dg.goingto = goingto.text;

                                        dg.goingfrom = goingfrom.text;

                                        dg.reception = reception.text;

                                        dg.passengernames = passengernames.text;

                                        dg.numberofpassengers = numberofpassengers.text;

                                        dg.church = church.text;

 

                                        updateReservationsResult.token = reservationsService.commit();

 

 

 

 

                              }

                              public function SaveChanges(event:MouseEvent):void{

 

                                        // update mysql database

                                        objSend.chauffeur = chauffeur.text;

                                        objSend.howmanyvehicles = howmanyvehicles.text;

                                        objSend.typeofvehicle = typeofvehicle.text;

                                        objSend.paymentmethod = paymentmethod.text;

                                        objSend.goingto = goingto.text;

                                        objSend.goingfrom = goingfrom.text;

                                        objSend.reception = reception.text;

                                        objSend.passengernames = passengernames.text;

                                        objSend.numberofpassengers = numberofpassengers.text;

                                        objSend.church = church.text;

 

                                        updateDatabase.send(objSend);

 

                                        // close the window

                                        closeWindow();

 

                              }

                    ]]>

          </mx:Script>

          <mx:HTTPService url="http://localhost/update.php"

                                           id="updateDatabase"

                                           showBusyCursor="true"

                                           method="POST"

                                           resultFormat="text"

                                           result='Alert.show("Reservation Successfully Updated. Reservation May Take A Minute To Update")'

                                           />

          <mx:CallResponder id="updateReservationsResult"/>

          <reservationsservice:ReservationsService id="reservationsService"

                                                                                                               fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)"

                                                                                                               showBusyCursor="true"/>

</mx:TitleWindow>

 

 

 

My PHP Code

 

<?php

 

 

//SQL Connection Info - update with your database, username & password

 

 

$host  = "localhost";

$username = "username";

$password = "databasepassword";

$database = "databasename";

 

 

$conn = mysql_connect($host, $username, $password);

        mysql_select_db($database) or die( mysql_error() );

 

 

 

 

$id = $_POST['id'];

$chauffeur = $_POST['chauffeur'];

$howmanyvehicles = $_POST['howmanyvehicles'];

$typeofvehicle = $_POST['typeofvehicle'];

$paymentmethod = $_POST['paymentmethod'];

$goingto = $_POST['goingto'];

$goingfrom = $_POST['goingfrom'];

$reception = $_POST['reception'];

$passengernames = $_POST['passengernames'];

$numberofpassengers = $_POST['numberofpassengers'];

$church = $_POST['church'];

 

 

 

 

$query = "UPDATE database SET chauffeur = '$chauffeur', howmanyvehicles = '$howmanyvehicles', typeofvehicle = '$typeofvehicle', paymentmethod = '$paymentmethod', goingto = '$goingto', goingfrom = '$goingfrom', reception = '$reception', passengernames = '$passengernames', numberofpassengers = '$numberofpassengers', church = '$church' WHERE id = $id";

mysql_query($query);

echo "Reservation Updated";

mysql_close();

 

 

?>

 
Replies
  • Currently Being Moderated
    Apr 1, 2013 5:43 AM   in reply to DashawnPD242

    Have you tried adding a Fault function to the HTTPService to see what the error is?

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points