0 Replies Latest reply on Nov 1, 2011 12:46 PM by mar719

    Having a problem with adding data to database from Form...Hoping someone can help...Thanks!

    mar719

      Hello. I wondering if someone would be able to figure out a problem I am having with adding data to a database. I am fairly new to Flex programming with some PHP skills.  I have taken the bulk of the Flex training courses.

       

      Here is my problem;  I am using the Flex training examples to add, update, and delete records from a database table.  I can't seem to be able to ADD a record.  The examples I have followed are passing variables as int, and I need to add based on string...meaning the primary key of my table is a unique string, whereas the examples I followed used an int for the primary key.

       

      Please look at my code.  Thank you.

       

      This code represent the mysql table Projects.

      <?php

      /**

      * Represents an Projects entity..

      */

      class Projects

      {

          /**

           * @var string

           */

          public $project_id;

          /**

           * @var string

           */

          public $project_name;

          /**

           * @var string

           */

          public $service_type;

          /**

           * @var string

           */

          public $util_contact_name;

          /**

           * @var string

           */

          public $util_contact_phone1;

          /**

           * @var string

           */

          public $util_contact_phone2;

          /**

           * @var string

           */

          public $util_contact_fax;

          /**

           * @var string

           */

          public $util_contact_email;

          /**

           * @var string

           */

          public $mgr_contact_name;

          /**

           * @var string

           */

          public $mgr_contact_phone1;

          /**

           * @var string

           */

          public $mgr_contact_phone2;

          /**

           * @var string

           */

          public $mgr_contact_fax;

          /**

           * @var string

           */

          public $mgr_contact_email;

      }

       

      This is the Service code that calls createProject() to add a record:

      public function createProject (Projects $item)

          {

              $stmt = mysqli_prepare($this->connection,

              "INSERT INTO projects (

              project_id,project_name,service_type,util_contact_name,util_contact_phone1,util_contact_p hone2,

                          util_contact_fax,util_contact_email,mgr_contact_name,mgr_contact_phone1,mgr_con tact_phone2,mgr_contact_fax,

                          mgr_contact_email)

      VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");

              $this->throwExceptionOnError();

              mysqli_bind_param($stmt, $item->project_id,$item->project_name, $item->service_type,

              $item->util_contact_name, $item->util_contact_phone1, $item->util_contact_phone2,

              $item->util_contact_fax, $item->util_contact_email, $item->mgr_contact_name, $item->mgr_contact_phone1,

              $item->mgr_contact_phone2, $item->mgr_contact_fax, $item->mgr_contact_email);

              $this->throwExceptionOnError();

              mysqli_stmt_execute($stmt);

              $this->throwExceptionOnError();

              $autoid = mysqli_stmt_insert_id($stmt);

              mysqli_stmt_free_result($stmt);

              mysqli_close($this->connection);

              return $autoid;

          }

       

      Procedures for createProjectResult:

      protected function button_clickHandler(event:MouseEvent):void

                                    {

                                              projects.project_id = project_idTextInput.text;

                                              projects.project_name = project_nameTextInput.text;

                                              projects.service_type = service_typeTextInput.text;

                                              projects.util_contact_name = util_contact_nameTextInput.text;

                                              projects.util_contact_phone1 = util_contact_phone1TextInput.text;

                                              projects.util_contact_phone2 = util_contact_phone2TextInput.text;

                                              projects.util_contact_fax = util_contact_faxTextInput.text;

                                              projects.util_contact_email = util_contact_emailTextInput.text;

                                              projects.mgr_contact_name = mgr_contact_nameTextInput.text;

                                              projects.mgr_contact_phone1 = mgr_contact_phone1TextInput.text;

                                              projects.mgr_contact_phone2 = mgr_contact_phone2TextInput.text;

                                              projects.mgr_contact_fax = mgr_contact_faxTextInput.text;

                                              projects.mgr_contact_email = mgr_contact_emailTextInput.text;

                                              createProjectResult.token = projectsService.createProject(projects);

                                    }

                                    protected function createProjectResult_resultHandler(event:ResultEvent):void

                                    {           

                                              currentState="ProjectDetails";

                                              projects.project_id=event.result as String;

                                              projectDg.dataProvider.addItem(projects);

                                    }

       

      Lastly the Declarations:

      <fx:Declarations>

                          <s:CallResponder id="getProjectsResult"

                                                                   result="projects = getProjectsResult.lastResult[0] as Projects;

                                                                   projects = getProjectsResult.lastResult[0] as Projects;

                                                                   projects = getProjectsResult.lastResult[0] as Projects;

                                                                   projects = getProjectsResult.lastResult[0] as Projects"/>

                          <projectsservice:ProjectsService id="projectsService"

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

                                                                                                           showBusyCursor="true"/>

                          <valueObjects:Projects id="projects"/>

                          <s:CallResponder id="createProjectResult"

                                                                   result="createProjectResult_resultHandler(event)"/>

                </fx:Declarations>

       

       

      Any help would be appreciated, thank you.