2 Replies Latest reply on Jul 11, 2007 12:27 PM by Newsgroup_User

    httpservice doesn't work!!! HELP!!!!

    tolson77r Level 1
      I want to create a simple form to update a mysql database using php. The flex file pulls data from the database but the insert won't work. I am at wits end!!! I have attached the mxml file and the php file. Please anybody help me out!!!

      MXML File
      --------------------------
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute" creationComplete="invoiceRequest.send()">
      <mx:Script>
      <![CDATA[
      import mx.utils.ArrayUtil;
      import mx.collections.*;
      import mx.rpc.events.*;
      ]]>
      </mx:Script>
      <mx:HTTPService id="invoiceRequest" url=" http://localhost/invoice/bin/invoice_action.php" useProxy="false" method="POST">
      <mx:request xmlns=""><first_name>{first_name.text}</first_name>
      <last_name>{last_name.text}</last_name>
      <company_name>{company_name.text}</company_name>
      <address>{address.text}</address>
      <address2>{address2.text}</address2>
      <city>{city.text}</city>
      <state>{state.text}</state>
      <zip>{zip.text}</zip>
      <phone_area>{phone_area.text}</phone_area>
      <phone_first>{phone_first.text}</phone_first>
      <phone_last>{phone_last.text}</phone_last>
      <cell_area>{cell_area.text}</cell_area>
      <cell_first>{cell_first.text}</cell_first>
      <cell_last>{cell_last.text}</cell_last>
      <work_area>{work_area.text}</work_area>
      <work_first>{work_first.text}</work_first>
      <work_last>{work_last.text}</work_last>
      <email>{email.text}</email>
      </mx:request>
      </mx:HTTPService>
      <mx:Form x="22" y="10" width="493" height="441">
      <mx:HBox>
      <mx:Label text="First Name"/>
      <mx:TextInput id="first_name"/>
      </mx:HBox>
      <mx:HBox>
      <mx:Label text="Last Name"/>
      <mx:TextInput id="last_name"/>
      </mx:HBox>
      <mx:FormItem label="Company">
      <mx:TextInput id="company_name"/>
      </mx:FormItem>
      <mx:FormItem label="Address">
      <mx:TextInput id="address"/>
      </mx:FormItem>
      <mx:FormItem label="Address 2">
      <mx:TextInput id="address2"/>
      </mx:FormItem>
      <mx:FormItem label="City, State, Zip" width="416">
      <mx:HBox width="100%" height="100%">
      <mx:TextInput width="100" id="city"/>
      <mx:TextInput width="100" id="state"/>
      <mx:TextInput width="50" id="zip"/>
      </mx:HBox>
      </mx:FormItem>
      <mx:FormItem label="Home Phone">
      <mx:HBox width="314" height="100%">
      <mx:TextInput width="20" id="phone_area"/>
      <mx:TextInput width="20" id="phone_first"/>
      <mx:TextInput width="20" id="phone_last"/>
      </mx:HBox>
      </mx:FormItem>
      <mx:FormItem label="Cell Phone" width="417">
      <mx:HBox width="100%" height="100%">
      <mx:TextInput width="20" id="cell_area"/>
      <mx:TextInput width="20" id="cell_first"/>
      <mx:TextInput width="20" id="cell_last"/>
      </mx:HBox>
      </mx:FormItem>
      <mx:FormItem label="Work Phone">
      <mx:HBox width="316" height="100%">
      <mx:TextInput width="20" id="work_area"/>
      <mx:TextInput width="20" id="work_first"/>
      <mx:TextInput width="20" id="work_last"/>
      </mx:HBox>
      </mx:FormItem>
      <mx:FormItem label="Email">
      <mx:TextInput id="email"/>
      </mx:FormItem>
      <mx:Button label="Submit" click="invoiceRequest.send()"/>
      </mx:Form>
      <mx:DataGrid id="dgInvoiceRequest" x="523" y="10" dataProvider="{invoiceRequest.lastResult.invoices.invoice}">
      <mx:columns>
      <mx:DataGridColumn headerText="First Name" dataField="first_name"/>
      <mx:DataGridColumn headerText="Last Name" dataField="last_name"/>
      </mx:columns>
      </mx:DataGrid>
      </mx:Application>


      PHP File
      ---------------------------------
      <?php
      define( "DATABASE_SERVER", "localhost" );
      define( "DATABASE_USERNAME", "uksurf77" );
      define( "DATABASE_PASSWORD", "LLaser2" );
      define( "DATABASE_NAME", "invoice" );

      //connect to the database
      $mysql = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD);

      mysql_select_db( DATABASE_NAME );

      // Quote variable to make safe
      function quote_smart($value)
      {
      // Stripslashes
      if (get_magic_quotes_gpc()) {
      $value = stripslashes($value);
      }
      // Quote if not integer
      if (!is_numeric($value)) {
      $value = "'" . mysql_real_escape_string($value) . "'";
      }
      return $value;
      }

      if( $_POST["first_name"] AND $_POST["last_name"])
      {
      //add the user
      $Query = sprintf("INSERT INTO clients VALUES ('', %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", quote_smart($_POST['first_name']), quote_smart($_POST['last_name']), quote_smart($_POST['company_name']), quote_smart($_POST['address']), quote_smart($_POST['city']), quote_smart($_POST['state']), quote_smart($_POST['zip']), quote_smart($_POST['phone_area']), quote_smart($_POST['phone_first']), quote_smart($_POST['phone_last']), quote_smart($_POST['cell_area']), quote_smart($_POST['cell_first']), quote_smart($_POST['cell_last']), quote_smart($_POST['work_area']), quote_smart($_POST['work_first']), quote_smart($_POST['work_last']), quote_smart($_POST['email']));


      $Result = mysql_query( $Query );
      }

      //return a list of all the users
      $Query = "SELECT * from clients";
      $Result = mysql_query( $Query );

      $Return = "<invoices>";

      while ( $Invoice = mysql_fetch_object( $Result ) )
      {
      $Return .= "
      <invoice>
      <client_id>".$Invoice->client_id."</client_id>
      <first_name>".$Invoice->first_name."</first_name>
      <last_name>".$Invoice->last_name."</last_name>
      <company_name>".$Invoice->company_name."</company_name>
      <address>".$Invoice->address."</address>
      <address2>".$Invoice->address2."</address2>
      <city>".$Invoice->city."</city>
      <state>".$Invoice->state."</state>
      <zip>".$Invoice->zip."</zip>
      <phone_area>".$Invoice->phone_area."</phone_area>
      <phone_first>".$Invoice->phone_first."</phone_first>
      <phone_last>".$Invoice->phone_last."</phone_last>
      <cell_area>".$Invoice->cell_area."</cell_area>
      <cell_first>".$Invoice->cell_first."</cell_first>
      <cell_last>".$Invoice->cell_last."</cell_last>
      <work_area>".$Invoice->work_area."</work_area>
      <work_first>".$Invoice->work_first."</work_first>
      <work_last>".$Invoice->work_last."</work_last>
      <email>".$Invoice->email."</email>
      </invoice>";
      }
      $Return .= "</invoices>";
      mysql_free_result( $Result );
      print ($Return)
      ?>