3 Replies Latest reply: Apr 4, 2013 10:35 PM by DashawnPD242 RSS

    Save Changes to MySQL After Updating

    DashawnPD242

      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.reservationsservice.*"

                                              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();

       

       

      ?>